Reputation: 13
uint16_t a = 0x00 << 8 + 0xB9;
printf("%d",a);
I'm expecting 185
as an output but I'm getting 0
.
What is happening here?
Upvotes: 1
Views: 77
Reputation: 2383
If you look at this link, you'll see that the order of precedence means that the addition is performed before the shift. Change your code to
uint16_t a = (0x00 << 8) + 0xB9;
printf("%d",a);
to see the desired behaviour.
Upvotes: 5