## Thursday, May 1, 2014

### Program to find binary value using bitwise operator in C!!!

```/*************************************************
* This program finds the binary value of the given integer value
* Used bitwise operators to find binary value
* Below is the logic to find binary value
* 1. Need to skip right most 0'1 until 1 comes
* 2. After that, do AND operation with MASK value  print 1 on true else 0
* 3. Shift one bit left
* 4. Repeat step 2 Until Int size completes
*
*
* Int size is generally 4 bytes which is 32 bits
* MASK value for Int is in hexa (0x80000000)
* Above mask value is taken, because we need to mask Most significant bit (31st bit)
*
*************************************************/

#define INT_SIZE 32
#include&amp;lt;stdio.h&amp;gt;
void findBinary(int num)
{
int pos;
int i=0;
int flag = 0;

//finding location from right side
//so that we can ignore zeros
//e.g: 0000100 same as 100, ignore 0000
// ANDing
for(i=0;i&amp;lt;INT_SIZE;i++)
{
{
if(!flag)
{
pos = i;
break;
}
}
}
printf("\nBinary value is ");
for(i=pos;i&amp;lt;INT_SIZE;i++)
{
printf("1");
else
printf("0");
}
printf("\n");

}
int main()
{
int x = 0;
printf("Enter input value\n");
scanf("%d",&amp;x);
findBinary(x);
}
```
`OutPut:`
```Enter input value
256
Binary value is 100000000```

```Enter input value
234
Binary value is 11101010```

`Happy Coding!!!`