Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java binary count

Tags:

java

binary

I need to know how to figure out the result of the SOUT without using of PC.

public static int bits(int n) {
    return n & (0xeeeeeeee|0x66666666);
}

What does it return for bits(6);? I know it returns 6, but why?

like image 271
q99 Avatar asked Nov 27 '25 16:11

q99


1 Answers

Convert the hexadecimal literals to binary literals by hand and then it will become more clear.

As this is homework, I think that this is an appropriate enough answer without giving too many details away.

like image 150
Zéychin Avatar answered Nov 30 '25 07:11

Zéychin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!