Binary Representation: Unsigned and 2’s Complement
Computer’s don’t use languages like humans, such as Chinese or English. Computers use 1’s and 0’s to read and write information. So exactly how do they do that?
One of the most basic things is how they represent numbers. If you have a large enough number to work with, you can assign numbers to represent specific. This guide will explain how unsigned and 2’s complement binary representations work.
Unsigned Binary Representation
When we count decimal numbers (the normal numbers we’re used to), we move into the double digits. 8, 9, 10, 11…
Counting upwards in binary is the same concept, except we only have two numbers, 1 and 0. So, we go into double digits if we run out of ways to count upwards: 0, 1, 10, 11, 100…
So, using different combinations of 1’s and 0’s, we have 2ⁿ ways of representing numbers. For example, using 5 spaces of 1’s or 0’s, we can represent numbers from 00000 to 11111 (0 to 31). For every new 2ⁿ threshold (2, 4, 8, 16, 32, 64, 128…), we need another digit of 1’s and 0’s to store that number.
Convert Binary to Decimal
To convert a binary number to a decimal number, all we need to do is some multiplication and addition. Let’s work through an example.
Here, we have the binary number 100101. Let’s assign each digit a number, going up from right to left.
The blue numbers represent the n in the 2ⁿ we need to solve. Let’s calculate 2ⁿ for each 1 in the number.
We can then add each 2ⁿ number with 1’s. Here, we add 32, 4, and 1.
So, 100101 (binary) = 37 (decimal)
Convert Decimal to Binary
Converting decimal numbers to binary numbers is a little trickier. We still use 2ⁿ numbers, but it’s more of a guess-and-check process.
Let’s run through an example, and convert the number 349.
The largest 2ⁿ I can squeeze in 349 is n=8, or 2⁸=256. So, let’s draw out 8 boxes, each to represent a different 2ⁿ for each n.
Then, we subtract 256 from 349. 349–256=93.
Since the number is greater than or equal to 256, we can place a 1 in the 8th box of the number. Then, we can continue to the next box.
2⁷=128>93, so we will put a 0 in the 7th box and move the next one.
Get Albert Xu’s stories in your inbox
Join Medium for free to get updates from this writer.
2⁶=64<93, so we will subtract the value and place a 1 in the box. 93–64=29.
Continuing on until we reach the end, we will end up with a final subtracted number, and a completed binary representation for the original decimal number.
So, 349 (decimal) = 101011101 (binary)
2’s Complement Representation
Understanding 2’s complement after understanding unsigned binary representation is very easy. 2’s complement is just a method to represent negative numbers, in addition to positive numbers.
In 2’s complement representation, we look at the first digit of the binary number to determine if it is positive or negative. If the number is position, the number will start with 0. If the number is negative, the number will start with 1.
However, there IS a specific procedure to convert the numbers. For example, 11111 in 2’s complement is -1 (decimal), not -15 or -31. This is to make addition, subtraction, and even multiplication possible with 2’s complement.
Note that while 2’s complement can hold the same amount of numbers as ordinary binary representation (2ⁿ numbers with n digits), the numbers stored are always smaller than normal binary representation. Recall that using 5 digits, you can represent 00000 to 11111 (0 to 31). Using 2’s complement and 5 digits, you can only represent 10000 to 01111 (-16 to 15).
2’s Complement to Decimal
To convert a 2’s complement representation into a readable number format, follow these steps:
- If the number is positive (the most significant bit is 0), convert the number into decimal format normally.
- If the number is negative, flip all the digits in the number. In other words, change all the 1’s to 0’s and all the 0’s to 1's.
- Add 1 to the flipped number.
- To see the number in decimal format, just convert it to a decimal number like in regular binary representation.
For example, let’s convert 10110110.
- Since the most significant bit is 1, we need to flip the digits in the number.
- 10110110 → 01001001.
- Add 1 to the number. 01001001+1=01001010.
- 01001010 (binary) = 74 (decimal).
So, 10110110 (2’s complement)=-74 (decimal).
Decimal to 2’s Complement
If we implement the steps from the previous part, but in reverse, we can convert a decimal number into a 2’s complement representation.
- If the number is positive, convert the number to binary representation normally. Make sure the binary number’s most significant digit is 0, because the number is positive.
- If the number is negative, convert the number to a binary representation as if they were a positive number.
- Subtract the number by 1.
- Flip all the digits in the number.
Let’s try an example with -93.
- The number is negative, so we will remember that.
- Convert 93 into a binary representation. 93 (binary)=01011101.
- Subtract the number by 1. 01011101–1=01011100.
- Flip the digits. 01011100→10100011.
So, -93 (decimal)=10100011 (2’s complement)








