C Programming - Bitwise Operators - Discussion
Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 9)
9.
What will be the output of the program ?
#include<stdio.h>
int main()
{
int i=32, j=0x20, k, l, m;
k=i|j;
l=i&j;
m=k^l;
printf("%d, %d, %d, %d, %d\n", i, j, k, l, m);
return 0;
}
Discussion:
28 comments Page 3 of 3.
Rams said:
1 decade ago
j=0x20=(20)H
hexadecimal to decimal=(2*16^1)+(0*16^0)=32+0=32;
i=32;
j=32;
k=i|j=10000|10000=10000=32
l=1&j=10000&10000=32
m=k^i=10000^10000=00000=0
hexadecimal to decimal=(2*16^1)+(0*16^0)=32+0=32;
i=32;
j=32;
k=i|j=10000|10000=10000=32
l=1&j=10000&10000=32
m=k^i=10000^10000=00000=0
Vikram said:
1 decade ago
i=32 =00100000
j=0x20=00100000
k=i(or)j ----> o/p is 32.
l=i(and)j -----> o/p is 32.
m=k(xor)j -----> o/p is o. since if both of i/P's are equal then o/p is low in xor logic.
hence o/p is
i,j,k,l,m = 32,32,32,32,0.
Thank you.
j=0x20=00100000
k=i(or)j ----> o/p is 32.
l=i(and)j -----> o/p is 32.
m=k(xor)j -----> o/p is o. since if both of i/P's are equal then o/p is low in xor logic.
hence o/p is
i,j,k,l,m = 32,32,32,32,0.
Thank you.
Anil said:
1 decade ago
Please explain 0x20 = 32 happens?
Jegan x said:
1 decade ago
In or operator 1+1 = 10 ? what will print for k.
Priyanka said:
1 decade ago
Someone please explain how 0*20 means 2 hexa decimals.
Rajeev kuamr said:
1 decade ago
Give me some more concept about convertion of hexadecimal to decimal.
Kunal said:
1 decade ago
Here one number is given in decimal and one in hexadecimal so, to get the result either convert decimal to hexadecimal or vice versa.
Now converting hexadecimal 0x20 to decimal as 2*16^1+0*16^0=32
Now convert it into binary to get the result.
Now converting hexadecimal 0x20 to decimal as 2*16^1+0*16^0=32
Now convert it into binary to get the result.
Raju said:
2 decades ago
Here j=0x20 means 2 hexa decimals i,e 2*16=32, So now j=32 and given i value also 32.
i=32 --> 100000
j=32 --> 100000
i|j --> 100000, So k=32 (applying | operator)
i&j --> 100000, So l=32 (applying & operator)
k^l --> 000000, So m=0 (applying ^ operator).
i=32 --> 100000
j=32 --> 100000
i|j --> 100000, So k=32 (applying | operator)
i&j --> 100000, So l=32 (applying & operator)
k^l --> 000000, So m=0 (applying ^ operator).
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers