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 */
// ?????????
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With