networking · intermediate · ~15 min
Serialise a 16-bit value to network order.
Implement void htons_bytes(unsigned short x, unsigned char *out) writing x as two big-endian bytes (out[0] high, out[1] low) — host-independent.
void htons_bytes(unsigned short x, unsigned char *out) {
/* TODO */
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.