cybersecurity · intermediate · ~15 min · safe pentest lab

Read a little-endian uint32

Decode an LE32 value.

Challenge

Decode a 32-bit little-endian integer from 4 bytes — the building block for parsing pcap and most binary file formats.

Task

Implement unsigned read_le32(const unsigned char *b) that assembles a 32-bit value from the 4 bytes at b, where b[0] is the least significant byte.

Input

  • b: a byte buffer of at least 4 bytes. The grader passes a fixed buffer.

Output

Returns unsigned: b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24).

Example

b = 0x78 0x56 0x34 0x12
read_le32(b)   ->   0x12345678

Edge cases

  • All-zero bytes give 0.
  • Cast each byte to unsigned before shifting to avoid sign issues.

Input format

A byte buffer b of at least 4 bytes.

Output format

An unsigned: the 4 bytes assembled little-endian (b[0] least significant).

Constraints

b[0] is the low byte. Cast to unsigned before shifting.

Starter code

unsigned read_le32(const unsigned char *b) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.