Two's Complement

To solve the issues of signed arithmetic, two’s complement is a method of encoding signed integers such that the most significant bit indicates the sign, and negative numbers are represented by inverting all bits of the absolute value and adding one. This method simplifies arithmetic operations and comparison of signed integers. To convert a number into its Two’s Complement:

  1. Start with the absolute signed binary representation of the number.
  2. Invert all bits.
  3. Add 1 to the entire number and ignore overflow.

Intuition

Let’s take a look at how Two’s Complement actually works. Suppose we have a 4-bit integer. Let that integer be . We can invert it to get . We can then add to get .

Notice that we can only use the first 3 bits for positive numbers, and all 4 bits for negative numbers. Therefore, the range that we can represent using two’s complement appears to be . That’s one more number than the signed integer representation! Notice that this is because we only represent 0 using :

\begin{document}
\begin{tikzpicture}
 
% Draw the circle
\draw[thick] (0,0) circle (3cm);
 
% Define positions and labels manually
\node[anchor=center] at (90:3cm) {};
\node[anchor=south] at (90:3.2cm) {0000};
\node[anchor=north] at (90:2.8cm) {0};
 
\node[anchor=center] at (112.5:3cm) {};
\node[anchor=south] at (112.5:3.2cm) {0001};
\node[anchor=north] at (112.5:2.8cm) {1};
 
\node[anchor=center] at (135:3cm) {};
\node[anchor=south] at (135:3.2cm) {0010};
\node[anchor=north] at (135:2.8cm) {2};
 
\node[anchor=center] at (157.5:3cm) {};
\node[anchor=south] at (157.5:3.2cm) {0011};
\node[anchor=north] at (157.5:2.8cm) {3};
 
\node[anchor=center] at (180:3cm) {};
\node[anchor=south] at (180:3.2cm) {0100};
\node[anchor=north] at (180:2.8cm) {4};
 
\node[anchor=center] at (202.5:3cm) {};
\node[anchor=south] at (202.5:3.2cm) {0101};
\node[anchor=north] at (202.5:2.8cm) {5};
 
\node[anchor=center] at (225:3cm) {};
\node[anchor=south] at (225:3.2cm) {0110};
\node[anchor=north] at (225:2.8cm) {6};
 
\node[anchor=center] at (247.5:3cm) {};
\node[anchor=south] at (247.5:3.2cm) {0111};
\node[anchor=north] at (247.5:2.8cm) {7};
 
\node[anchor=center] at (270:3cm) {};
\node[anchor=south] at (270:3.2cm) {1000};
\node[anchor=north] at (270:2.8cm) {-8};
 
\node[anchor=center] at (292.5:3cm) {};
\node[anchor=south] at (292.5:3.2cm) {1001};
\node[anchor=north] at (292.5:2.8cm) {-7};
 
\node[anchor=center] at (315:3cm) {};
\node[anchor=south] at (315:3.2cm) {1010};
\node[anchor=north] at (315:2.8cm) {-6};
 
\node[anchor=center] at (337.5:3cm) {};
\node[anchor=south] at (337.5:3.2cm) {1011};
\node[anchor=north] at (337.5:2.8cm) {-5};
 
\node[anchor=center] at (0:3cm) {};
\node[anchor=south] at (0:3.2cm) {1100};
\node[anchor=north] at (0:2.8cm) {-4};
 
\node[anchor=center] at (22.5:3cm) {};
\node[anchor=south] at (22.5:3.2cm) {1101};
\node[anchor=north] at (22.5:2.8cm) {-3};
 
\node[anchor=center] at (45:3cm) {};
\node[anchor=south] at (45:3.2cm) {1110};
\node[anchor=north] at (45:2.8cm) {-2};
 
\node[anchor=center] at (67.5:3cm) {};
\node[anchor=south] at (67.5:3.2cm) {1111};
\node[anchor=north] at (67.5:2.8cm) {-1};
 
\end{tikzpicture}
\end{document}