I was trying to understand someone's code yesterday and came across this segment
ByteBuffer pixels = ByteBuffer.allocateDirect(256 * 256 * 4);
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
int value = perm[(j + perm) & 0xFF];
//System.out.println(value);
pixels.put((byte) (grad3[value & 0x0F][0] * 64 + 64)); // Gradient x
pixels.put((byte) (grad3[value & 0x0F][1] * 64 + 64)); // Gradient y
pixels.put((byte) (grad3[value & 0x0F][2] * 64 + 64)); // Gradient z
pixels.put((byte) (value)); // Permuted index
}
}
pixels.rewind();I am still very new to the idea of bytes and was wondering what "& 0xFF" and "value & 0x0F" did so that I can understand what kind of value will be inserted into the Byte Buffer.
Thanks for your help