// create a mask of 1s 24 bits wide. int mask24 = 0x00ffffff; // or int mask24 = ( 1 << 24 ) - 1; // watch out, formula does not work for 32 // use it to extract the low order 3 bytes v &= mask24; // create a mask of 0s 24 bits wide, the rest 1s int mask024 = 0xff000000; // or int mask024 = ~0x00ffffff; // or int mask024 = ~( ( 1 << 24 ) - 1 ); // watch out, formula does not work for 32 // use it to extract the high order byte v = ( v & mask024) >>> 24; // create a mask of ones to extract the second lowest byte int mask2 = 0x0000ff00; // or int mask2 = ( ( 1 << 8 ) - 1 ) << 8; // use it to grab that byte v = ( v & mask2 ) >>> 8; // create mask for clearing the second lowest byte int clear2 = 0xffff00ff; // or int clear2 = ~(( ( 1 << 8 ) - 1 ) << 8 ); // use it to clear that byte and leave everything else alone with v &= clear2;