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;
}
Discussion:
66 comments Page 5 of 7.
Divya S said:
1 decade ago
Nice explanation kasi. Thanks.
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
0000 0000 1000 0000
now left shift 1 byte means
0000 0001 0000 0000=256
ULLAS K said:
1 decade ago
@nikita.
Bitwise operator can't be applied to float and double type. This its limitation,
Check out in books.
Bitwise operator can't be applied to float and double type. This its limitation,
Check out in books.
SRINIVAS said:
1 decade ago
Good.Nice Explanation Without having any doubts.Thank you
Yachana said:
1 decade ago
Why you are taking 2 bytes instead of 1 byte.
Raj said:
1 decade ago
0x80 is hex representation and its binary equivalent is 1000 0000
Tomek said:
2 decades ago
I got caught because I thought there would be overflow and it becomes 0. But char is converted to int before <<
Shruti said:
2 decades ago
What is 0x80?
How do we conver it to binary?
How do we conver it to binary?
Madureddy said:
2 decades ago
Yes Kasi is correct.
Kasi said:
2 decades ago
i = 0x80 = 00000000 10000000 in binary form.
After i<<1 it becomes 00000001 00000000. Its decimal equivallent is 256.
After i<<1 it becomes 00000001 00000000. Its decimal equivallent is 256.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers