I need some help understanding the follow functions & how they work.

1) y >> 16 & 0xFF0
2) (y >> 16 & 0xFFC) << 4
3) (y >> 20 & 0xF0F) | 1 << 7

Recommended Answers

All 5 Replies

What do you think they do? If you try to explain them, we'll tell you where you got it wrong.

well, from what I know, the
1st one is
shift y by 16 & 0xFF0

2nd is
shift y by 16 & 0xFFC then shift left by 4

3rd
shift y by 20 & 0xF0F then comparing with 1 using XOR & then shift left by 4

pls let me know if im wrong here

Correct on the first 2.
Wrong on last one. There's no compare and no XOR...

But what do they mean

Just using the first example:
y >> 16 & 0xFF0 // y is shifted right by 16 bits, then bitwise and with bitmask 0xFF0

e.g 0xBEEFC000 >> 16 = 0xBEEF
0xBEEF & 0xFF0 = 0xEE0

FWIW, the XOR operator is ^ as in (0xCAFEFACE ^ 0xECAFEFAC). The | symbol is the OR operator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.