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 2 of 3.
Amit said:
10 years ago
Hi @Charu.
Question--> 0*80 = 128.
Answer --> Firstly we will separate 80 in 8 and 0.
After that the binary number's of 8 and 0 are:
8 = 1000.
0 = 0000.
Then combine these number's.
80 = 1000 0000.
After that we will make decimal number for 1000 0000 with the help of this,
128 64 32 16 8 4 2 1.
So 1000 0000 = 128.
Finally 0*80 = 128.
Question--> 0*80 = 128.
Answer --> Firstly we will separate 80 in 8 and 0.
After that the binary number's of 8 and 0 are:
8 = 1000.
0 = 0000.
Then combine these number's.
80 = 1000 0000.
After that we will make decimal number for 1000 0000 with the help of this,
128 64 32 16 8 4 2 1.
So 1000 0000 = 128.
Finally 0*80 = 128.
Basamma said:
10 years ago
Hi @Charu.
We can write 80 as 1000 0000.
Now assigning decimal value to above binary number as:
128 64 32 16 8 4 2 1.
Means --> Value of 0*80 is 128.
We can write 80 as 1000 0000.
Now assigning decimal value to above binary number as:
128 64 32 16 8 4 2 1.
Means --> Value of 0*80 is 128.
Charu said:
1 decade ago
Please explain the value of 0*80?
Amit said:
1 decade ago
I think.
B = B10101010; // B10101010 == 0xAA.
We can break this binary code in two parts 1010 and 1010.
Means B10101010 so 1010 = A and another 1010 = A.
So we can use it as like 0x20.
Means 2 = 0010 and 0 = 0000.
Means 00100000 = 32.
So finally 0x20 = 0010 0000 = 32.
B = B10101010; // B10101010 == 0xAA.
We can break this binary code in two parts 1010 and 1010.
Means B10101010 so 1010 = A and another 1010 = A.
So we can use it as like 0x20.
Means 2 = 0010 and 0 = 0000.
Means 00100000 = 32.
So finally 0x20 = 0010 0000 = 32.
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).
Abhinav said:
1 decade ago
What does x means 0x20?
SONU said:
1 decade ago
In binary:
1=0000
2=0010
3=0011
4=0100
5=0101
6=0110
7=0111
.......
15=1111.
For decimal to binary:
0110 = start from left
0x 2(power 0)+1x 2(power 1)+1x 2(power 2)+0x 2(power3) = 0+2+4+0 = 6.
For decimal to hexadecimal:
1=1
2=2
3=3
4=4
5=5
6=6
7=7
8=8
9=9
10=A
11=B
12=C
13=D
14=E
15=F
May IT help you @UDAY.
1=0000
2=0010
3=0011
4=0100
5=0101
6=0110
7=0111
.......
15=1111.
For decimal to binary:
0110 = start from left
0x 2(power 0)+1x 2(power 1)+1x 2(power 2)+0x 2(power3) = 0+2+4+0 = 6.
For decimal to hexadecimal:
1=1
2=2
3=3
4=4
5=5
6=6
7=7
8=8
9=9
10=A
11=B
12=C
13=D
14=E
15=F
May IT help you @UDAY.
Uday said:
1 decade ago
Please explain conversions on binary to decimal and decimal to hexadecimal and vice versa.
Bhagyashri Ghalme said:
1 decade ago
I am not satisfied by the above answer. So please somebody help me to get perfect answer of the above question.
Arup said:
1 decade ago
@Priyanka
0x20 is a hexadecimal number
First convert to Binary i.e 0010 0000 and make to decimal i.e. 32
0x20 is a hexadecimal number
First convert to Binary i.e 0010 0000 and make to decimal i.e. 32
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers