Reading about binary operations in Java i'm stack of next example :
10111011 & 00001000 = 00001000
00001000 is a 8 in decimal represenation
but when i try to execute the following code :
System.out.println("10111011 & 00001000 = " + (0b10111011 & 0b00001000));
System.out.println("10111011 & 00001000 = " + Integer.toString(0b10111011 & 0b00001000, 2));
i getting output :
10111011 & 00001000 = 8 // right!
10111011 & 00001000 = 1000 // not a 00001000!
So i have 2 questions :
1) Why when i make conjunction operations i have invalid result?(My mistake)
2) Why in output i have only part visible of bits? How i can see all of bits count? Why Integer.toString(value,radix) doesn't return full record as 00001000?
4? 2. Why would it show more bits than necessary; how many zeroes would you have liked?!4bit set for a bitwise and sure isn't going to have it set in the result. Because leading zeros aren't significant? You probably want to format it.