I am having an issue trying to find the bit-wise values of a Java byte type. When I try to obtain the value of a certain number of bits by using the bit-wise operator & this value is not the way I foresee it. The (very simple) code is as follows:
public class Demo
public static void main(Stringarg)
byte demo = 127;
System.out.println("demo is: "+(demo & 00000011));
As Patricia already pointed out: Java interpretes numbers starteing with leading zeros as being octal values.
If you want the number to be binary, mark it with a leading "0b":
System.out.println("demo is: "+(demo & 0b00000011));