Is one's complement a real-world issue, or just a historical one?

后端 未结 9 794
广开言路
广开言路 2020-11-29 04:53

Another question asked about determining odd/evenness in C, and the idiomatic (x & 1) approach was correctly flagged as broken for one\'s complement-based systems, which

9条回答
  •  攒了一身酷
    2020-11-29 05:24

    RFC 791 p.14 defines the IP header checksum as:

    The checksum field is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header. For purposes of computing the checksum, the value of the checksum field is zero.

    So one's complement is still heavily used in the real world, in every single IP packet that is sent. :)

提交回复
热议问题