I want to get the lowest bytes of an uint16_t
in C.
Example:
20544 = 0x5040
0x40 = 64
I tried, (X & ((1<<2) - 1))
. This doesn't work for me.
You use bytes (plural), but a uint16_t
is composed of two bytes, so I'm assuming you mean the least significant byte (singular). If that's so, here is one way of obtaining it:
uint8_t lsb = ((uint8_t)(((uint32_t)(val)) & 0xFF))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.