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 1 of 7.

Kee said:   2 decades ago
Pleases give the step.

Kasi said:   2 decades ago
i = 0x80 = 00000000 10000000 in binary form.

After i<<1 it becomes 00000001 00000000. Its decimal equivallent is 256.

Madureddy said:   1 decade ago
Yes Kasi is correct.

Tomek said:   1 decade ago
I got caught because I thought there would be overflow and it becomes 0. But char is converted to int before <<

Shruti said:   1 decade ago
What is 0x80?

How do we conver it to binary?

Raj said:   1 decade ago
0x80 is hex representation and its binary equivalent is 1000 0000

Yachana said:   1 decade ago
Why you are taking 2 bytes instead of 1 byte.

SRINIVAS said:   1 decade ago
Good.Nice Explanation Without having any doubts.Thank you

Rashmi said:   1 decade ago
Yeah, how can we take two bytes for a character.

Swati said:   1 decade ago
0x88 means 128 in decimal hence
0000 0000 1000 0000
now left shift 1 byte means
0000 0001 0000 0000=256


Post your comments here:

Your comments will be displayed after verification.