/**
Program Name: AND Operation Between To Binary Numbers
Description: This Program Converts A Decimal Number to its Binary
Equivalent, using shift Operator, and also performs the
"logical And" operation between them, and displays output.
Author: Tauqirul Haque
*/
void printBinary(int i);
int main()
{
int number, number2;
printf("Enter The Number : ");
scanf("%d",&number);
printf("Enter The Number : ");
scanf("%d",&number2);
printf(" \nA = : ",number);
printBinary(number);
printf(" \nB = : ",number);
printBinary(number2);
printf("\n==================================================");
printf(" \n\nA & B : ");
printBinary(number & number2);
printf("\n==================================================\n\n");
}
void printBinary(int number)
{
int mask;
int position;
int msb;
int bit;
int hexDiff = 0;
int intTotalByte = sizeof(int);
if(intTotalByte == 2)
{
msb = 15;
}
else
{
msb = 31;
}
for(position = msb; position >=0; position--)
{
mask = 1<
bit = (number & mask)?1:0;
printf("%d",bit);
hexDiff++;
if(hexDiff == 4)
{
printf(" ");
hexDiff = 0;
}
}
printf("\n");
}
Program Name: AND Operation Between To Binary Numbers
Description: This Program Converts A Decimal Number to its Binary
Equivalent, using shift Operator, and also performs the
"logical And" operation between them, and displays output.
Author: Tauqirul Haque
*/
void printBinary(int i);
int main()
{
int number, number2;
printf("Enter The Number : ");
scanf("%d",&number);
printf("Enter The Number : ");
scanf("%d",&number2);
printf(" \nA = : ",number);
printBinary(number);
printf(" \nB = : ",number);
printBinary(number2);
printf("\n==================================================");
printf(" \n\nA & B : ");
printBinary(number & number2);
printf("\n==================================================\n\n");
}
void printBinary(int number)
{
int mask;
int position;
int msb;
int bit;
int hexDiff = 0;
int intTotalByte = sizeof(int);
if(intTotalByte == 2)
{
msb = 15;
}
else
{
msb = 31;
}
for(position = msb; position >=0; position--)
{
mask = 1<
bit = (number & mask)?1:0;
printf("%d",bit);
hexDiff++;
if(hexDiff == 4)
{
printf(" ");
hexDiff = 0;
}
}
printf("\n");
}
Comments