How will you multiply two numbers using BITWISE operators ?

Questions by jagdeessh

Showing Answers 1 - 4 of 4 Answers

Following code snippet would do the required action:

#include<stdio.h>
main()
{
   int a,b,result;
   printf("nEnter the numbers to be multiplied :");
   scanf("%d%d",&a,&b);
   result=0;
   while(b != 0)               // Iterate the loop till b==0
   {
      if (b&01)               // Logical ANDing of the value of b with 01
         result=result+a; // Update the result with the new value of a.
      a<<=1;              // Left shifting the value contained in 'a' by 1.
      b>>=1;             // Right shifting the value contained in 'b' by 1.
   }
   printf("nResult:%d",result);
}

Suresh Reddy.V.V

thulasi

  • Jul 30th, 2015
 

Code
  1. #include <stdio.h>

  2.  

  3. int main()

  4. {

  5. unsigned int y=0x3fff;

  6. float s=0.063;

  7. unsigned int x=1,value,z;


  8. value=%u",x&y);


  9. multiple the 14 bit number with 0.063");

  10. z=value^s;

  11. printf("the obtained result is:&z");

  12. return 0;

  13. }

  14.  

  15.  

  16.  

  17.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions