Udp 'one' s complement

List all the integers that the 2−bit ones’ complement numeral system represents.
How can we find 10 ⊕ 10?

Hello Kenan

This question has more to do with binary arithmetic than networking. However, since you mention UDP’s use of one’s complement, I can tell you that one’s complement is used in calculating the checksum which is a 16-bit field included in a UDP datagram’s header.

In particular, the checksum calculation for UDP involves using the “one’s complement sum”.

In a “one’s complement sum”, the values to be added are first represented in binary. Then, they are added together bitwise. If a bit value in the sum is a ‘1’, it remains a ‘1’; if it is a ‘0’, it remains a ‘0’. If there is a carry out from the most significant bit, that carry is wrapped around and added to the sum. This is known as end-around carry.

The “one’s complement” of the sum is then calculated. This is done by inverting all the bits in the sum (changing 1s to 0s, and 0s to 1s). This value is the one’s complement checksum. This checksum is sent along with the data.

Upon reception, the receiver performs the same one’s complement sum operation on the data and the received checksum. If there are no transmission errors, the result should be a string of all '1’s. This is due to the property of one’s complement arithmetic, where adding a number to its one’s complement always results in a string of all '1’s.

This is an efficient way to detect errors because it can be done in hardware, and it detects many common types of errors, such as flipping bits and swapping bytes. It is, however, not foolproof and can miss some errors. It is just one of many methods used to ensure the reliable delivery of data over networks.

Now regarding your binary arithmetic question, the 2-bit ones’ complement numeral system can represent the following integers:

Binary Decimal
00 0
01 1
10 -2
11 -1

To find the XOR (⊕) operation for 10 and 10:

1 0
1 0

Result: 00

Remember XOR will return a 1 when both inputs are different, and will return 0 when both inputs are the same. In the case of the above calculation, both inputs are the same, so the result is 00.

I hope this has been helpful!