Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What does "& 0xFF" and "& 0x0F" mean

807600Nov 29 2007 — edited Jan 25 2008
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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2008
Added on Nov 29 2007
8 comments
2,653 views