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 4 of 7.
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.
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 <<
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.
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
Raj said:
1 decade ago
Not a single explanation was useful. If anyone knows correct explanation, please help us. Thank you.
Satish said:
1 decade ago
First We have to convert hexadecimal to Decimal.
Then we have to find the binary value of that.
Then we have to find the binary value of that.
ANUPA A said:
9 years ago
Please, someone clearly explain to me what does the bitwise operator<< actually does.
Mayuri said:
1 decade ago
Char is 1byte in size. Then why everyone having explanation assuming it is 2 byte ?
Nikita said:
1 decade ago
char converted to int before <<
What happens if float or double is there?
What happens if float or double is there?
Jasber said:
7 years ago
i=0x80 means( 0000 0000 1000 0000).
i<<1means (0000 0001 0000 0000)= 256.
i<<1means (0000 0001 0000 0000)= 256.
(6)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers