开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜