Question & Answer: If you had the C code int a = 68, what shifting operation could be done to m…..

15. If you had the C code int a = 68, what shifting operation could be done to multiply a by 64 without using multiplication?

If you had the C code int a = 68, what shifting operation could be done to multiply a by 64 without using multiplication?

Expert Answer

 

we have to use left shift operator(<<), if we want to multiply a by 64. 1 left shift means 21 = 2, hence if we want to multiply a by 64 we need to shift a by 6. because 26 = 64.

if we multiply 68 * 64 then result would be = 4352.

here i have written the Complete c program, which display the required result.

—————————————————————————————————————————————-

Note: Please note that the below program has been tested on ubuntu 16.04 system and compiled under gcc compiler. This code will also work on other IDE’s.

——————————————————————————————————————————————

Program:

—————————————————————————————————————————————–

#include<stdio.h>

int main()

{

int a = 68, res;

//we have to use left shift operator if we want to multiply a by 64
//1 left shift means 2^1 hence to multiply 64 we need to shift a by 6
//because 2 ^ 6 = 64

res = (a << 6);

//display result

printf(“%dn”, res);

return 0;

}

—————————————————————————————————————————————–

here is the output:

——

Still stressed from student homework?
Get quality assistance from academic writers!