Can someone explain the following line of code? Particularly, I don't get what (short) x & 0x3FF
does?
int num = ... //some number.
return (short) num & 0x3FF;
It zeros out the top bits of the number, such that the result is always between 0 and 1023. It's essentially the same thing as modulo(num, 1024) (for positive values of num).
Without seeing a broader context it's impossible to know why this is here, but that's what it does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With