C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 5)
5.
What will be the output of the program?
#include<stdio.h>

int main()
{
    unsigned char i = 0x80;
    printf("%d\n", i<<1);
    return 0;
}
0
256
100
80
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
65 comments Page 7 of 7.

Rajani R said:   7 years ago
Please someone explain this solution.

Keziahtabraham said:   7 years ago
0*80 means 0000 0000 1000 0000.

Then, one time left shift(i<<1):0000 0001 0000 0000
According to position 1 is at 8th position, then to convert binary to decimal, 2^8=256.
(3)

Jasber said:   6 years ago
i=0x80 means( 0000 0000 1000 0000).

i<<1means (0000 0001 0000 0000)= 256.
(6)

Namu said:   6 years ago
How 0x80 is converted into binary?
(4)

Mladen Saldanha said:   7 months ago
if were a larger type (e.g., int), 0x80 << 1 would be 256 (binary 100000000).
But the unsigned char is 8-bit, so the overflow bit is discarded, leaving 00000000 (0).
So, I think answer is 0


Post your comments here:

Your comments will be displayed after verification.