开发者

Java get first and last 2 byte from int var

开发者 https://www.devze.com 2023-03-28 00:36 出处:网络
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.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消