networking · intermediate · ~15 min
Decode a little-endian 16-bit value.
I/Q samples are often stored little-endian (least-significant byte first), the opposite of network byte order. Decode a little-endian 16-bit value from two bytes.
Implement int parse_le16(const unsigned char *b) that returns b[0] | (b[1] << 8) — b[0] is the LOW byte and b[1] the high byte.
A pointer b to at least 2 bytes.
Returns the reassembled 16-bit value.
{0x34, 0x12} -> 0x1234
{0xFF, 0x00} -> 255
b[0] | (b[1] << 8)).A pointer b to at least 2 bytes.
The 16-bit value b[0] | (b[1] << 8).
Little-endian: b[0] is the low byte, b[1] the high byte.
int parse_le16(const unsigned char *b) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.