One's-complement sum of 0x1234 and 0xABCD — parity and checksum

coreend-around carry

Answer

BE01

Why this example is worth doing

The one's-complement sum adds the carry out back into the low bit — the end-around carry — rather than discarding it. The page explains why that matters: the result becomes independent of the byte order in which the words were added, which is what lets the Internet checksum be computed incrementally and on either endianness. It is a small detail with a large consequence.

Try your own input in the Parity & checksum. Even and odd parity, one’s-complement sums and the Internet checksum, step by step.

How the answer is reached

16-bit one's-complement sum over 4 bytes

Adjacent octets are paired into big-endian 16-bit integers and added with end-around carry.

One’s-complement addition: whenever the total exceeds 0xFFFF the carry is added back into the low 16 bits. — 16-bit one's-complement sum over 4 bytes
WordRunning sum+ wordEnd-around carryNew running sum
0x12340x00000x1234no0x1234
0xABCD0x12340xBE01no0xBE01

One's-complement sum0xBE01RFC 1071 prints this value in its example

Checksum0x41FEthe complement of the sum — this is what goes in the packet

Verification0xBE01 — not 0xFFFFsumming the octets *including* the checksum field must give 0xFFFF

Warning:

This is the sum, not the checksum. Complement it to get the value a sender transmits.

Source: RFC 1071, "Computing the Internet Checksum"

Compare with

Open this example in the Parity & checksum

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • The parity bit is appended after the data bits, and a checksum is stated with the byte order it was summed in.

Sources

  • Hamming, “Error Detecting and Error Correcting Codes” (1950)
  • Braden, Borman and Partridge, RFC 1071, “Computing the Internet Checksum” (1988)