networking · intermediate · ~15 min

ntohs via bytes

Deserialise a 16-bit value from network order.

Challenge

Implement unsigned short ntohs_bytes(const unsigned char *in) reading two big-endian bytes back into a 16-bit host value.

Starter code

unsigned short ntohs_bytes(const unsigned char *in) {
    /* TODO */
    return 0;
}

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