Java get first and last 2 byte from int var
I want convert an int into 2 bytes representing that int.
Probably must use bitwise and bit shifting, but I dont know what to do.
int x; /* val to convert开发者_StackOverflow中文版 */
// ?????????
int b12; /* the first 2 bytes */
int b34; /* the last 2 bytes */
// Shift 16 bits to the right.
int b12 = x >>> 16;
// Zeroes the upper 16 bits.
int b34 = x & 0xffff;
int b12 = (x & 0xFFFF);
int b34 = (x >>> 16);
精彩评论