bit manipulation - Why java bitwise compliment not fliping properly? -
i have following code:
int b1 = 0b1011; b1 = ~b1; system.out.println(integer.tobinarystring(b1)); but not getting expected result i.e. 100
what getting 11111111111111111111111111110100.
can 1 please explain this?
you flipping integer consists of 4 bytes, i.e., 32 bits. first 28 bits 0. getting flipped, too, results in number get. before flipping:
b1 = 0b00000000000000000000000000001011 after flipping:
b1 = 11111111111111111111111111110100 in order rid of unwanted 1's logically , b1 after flipping bits:
b1 = ~b1 b1 = b1 & 0b1111
Comments
Post a Comment