Left shift and registers

Hello!

I have found this peice of code and i dont know what it does... can
anyone please briefly explain what this does to variable x? What
becomes of it?

1
2
int x = 0xff00;
x |= (10 << 8);


Thank you.
First it gives x a hex value, which in base 10 is 65280. In binary this is 1111111100000000. It then bitwise-ORs this value with the result of the number 10 left shifted 8 bits. 10 in binary is 0000000000001010. Left shifting this 8 bits gives us the binary value: 0000101000000000, which is 2560 as a decimal. When you OR this value with x, you get the following value:

1111111100000000
| 0000101000000000
------------------
1111111100000000

This leaves x untouched, so the value of stays at 65280 :/
Last edited on
Topic archived. No new replies allowed.