I have a problem while doing the AND operator using 0xff.
public Pixel(int x, int y, int p) {
this.x = x;
this.y = y;
pixelValue = p;
A = (byte) ((p>>24) & 0xff);
R = (byte) ((p>>16) & 0xff);
R = (byte) (R&0xff);
G = (byte) ((p>>8) & 0xff);
B =(byte) (p & 0xff);
printAll();
}
void printAll() {
System.out.println("A "+Integer.toBinaryString(A));
System.out.println(Byte.toUnsignedInt(A));
System.out.println("R "+Integer.toBinaryString(R));
System.out.println(Byte.toUnsignedInt(R));
System.out.println("G "+Integer.toBinaryString(G));
System.out.println(Byte.toUnsignedInt(G));
System.out.println("B "+Integer.toBinaryString(B));
System.out.println(Byte.toUnsignedInt(B));
System.out.println("pixelValue"+pixelValue);
System.out.println(Integer.toBinaryString((byte)(pixelValue)));
}
When doing Pixel p = new Pixel(0,0,2145687240);
I get
A 1111111
127
R 11111111111111111111111111100100
228
G 11111111111111111111111110010110
150
B 11111111111111111111111111001000
200
pixelValue-56
11111111111111111111111111001000
Question being, why are R, G and B filled with 1s? and why is A only 7 bits? why when calling &0xff I get 1111111111111111111111111100100? shouldn't this cancel everything but the first 8 bytes?