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;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.