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;
}
0, 0, 0, 0, 0
0, 32, 32, 32, 32
32, 32, 32, 32, 0
32, 32, 32, 32, 32
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
28 comments Page 1 of 3.

Nayan vekariya said:   4 years ago
0x20 means that,

16 * 2 = 32.
So that 32 = 100000.
32 = 100000.

K = 32 | 0x20 ==== 32 | 32 (true | true)
L = 32 & 0x20 ==== 32 & 32 (true & true)
M = 32 ^ 0x20 ==== 32 ^ 32 (true | false)

So that 32, 32, 0.

Ashutosg said:   5 years 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).

Lokesh said:   6 years ago
Here 0x20 means convert the decimal number to hexadecimal number we already know that 20 in hexadecimal as 32.

Sam said:   6 years ago
How 100000!?

100000=100000 (32)? the answer should be 1000000 (64).

Mayur said:   8 years ago
Your explanation is clear, Thanks @Raju.

BalaG said:   8 years ago
@Vikram.

Your explanation is clear, Thanks.

Manju said:   8 years ago
@Ashmita.

4 bits equal to 1 hexadecimal digit.

j variable having 0*20 is represented as 0010 0000 . Same as like integer variable i.
k value after OR operation both i and j get same result 32 value.
L also get 32 after performing AND operation b/t I & j;
then, k with XOR operation.

So, the result will be -> 32,32,32,32,32.

Sameer said:   9 years ago
@Ashmita. In C/C++ the hexadecimal numbers are written as 0x20. Here the 0x. Represents, it is a hexadecimal number Or hexadecimal numbers are always preceded by 0x.

Ashmita said:   9 years ago
Please explain 0x20 where is define 0*20 is a hexadecimal.

Amit said:   9 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.


Post your comments here:

Your comments will be displayed after verification.