What will be equivalent of this in Java?
for (i = (sizeof(num)*8-1); i; i--)
num is given number, not array. I want to reverse bits in integer.
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.
Java does not have
sizeof. Arrays have thelengthproperty, and many collections havesize()and similar things like that, but a linguisticsizeoffor any arbitrary object is both not supported and not needed.Related questions
Getting bits of an integer in LSB-MSB order
To get the bits of an integer from its least significant bit to its most significant bit, you can do something like this:
This prints:
So in this specific case, the
sizeof * 8translates toInteger.SIZE, "the number of bits used to represent an int value in two’s complement binary form". In Java, this is fixed at 32.