← Back to list

Understanding Binary Numbers and Two’s Complement

As you probably know, computers can work with just 1s and 0s, nothing more. So, we need to represent everything using 0s and 1s in…

Furkaankaraduman · 2026-07-05 15:31 · 2 claps · 3.3 min read
#computer-science #computer-architecture #low-level-programming #binary #programming
Open on Medium ↗
Wiki topics: 💻 · Programming 🔬 · Science · General 🏛️ · Architecture

Understanding Binary Numbers and Two’s Complement

As you probably know, computers can work with just 1s and 0s, nothing more. So, we need to represent everything using 0s and 1s in computers. We also need to perform arithmetic operations using the binary number system. To understand how computers perform arithmetic, we first need to understand how numbers are represented in binary.

In this article, I want to explain how operations such as addition and subtraction works in binary system and how to represent numbers in computers usinf 0s and 1s. I hope this article gives you a solid understanding of these concepts.

What is Binary Number System?

The binary number system is a numeral system that uses only two digits: 0 and 1. We use binary numbers in the computer world because electronic circuits are built from transistors, and a transistor naturally has two stable states: on and off. It is similar to the decimal system which has 10 digits instead of 2. In binary system, the representation of the numbers are structured in the same way in the decimal system.

In decimal system, each digit has a place value and has a value $x \times 10^{\text{significance}}$ where x is the digit. For example, $(5636)_{10} = 5 \times 10³ \plus 6 \times 10² \plus 3 \times 10¹ \plus 6 \times 10⁰$.

The binary numbers follow the same rule, we can find the decimal equivalence of the number $(101001)_2$ as $1 \times 2⁵ \plus 0 \times 2⁴ \plus 1 \times 2³ \plus 0 \times 2² \plus 0 \times 2¹ \plus 1 \times 2⁰ = (41)_2$.

If you observe the binary numbers, you can realize that the structure is the same: Just like in the decimal system, we increment the least significant digit first. When it reaches its maximum value, we carry to the next digit on the left. Let’s count up to 15 using binary 0 numbers:

0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111.

How to Add Binary Numbers?

Binary addition works exactly like decimal addition. We start the addition from right and at each step we calculate a carry and a digit for that place. $0 \plus 0$ will give us a sum 0 and carry 0, $0 \plus 1$ will give us a sum 1 and carry 0, $1 \plus 1$ will give us a sum 0 and carry 1.

Let’s do some examples on binary addition:

\begin{align} &\quad 0101 &&\quad 1111 &&\ &+ 0011 &&+ 0011 \ \cline{1-1} \cline{3-3} &\quad 1000 &&10010 \end{align}

\begin{align} &\quad 0011 &&\quad 1010 \ &+ 1001 &&+ 1011 \ \cline{1-1} \cline{3-3} &\quad 1100 &&10101 \end{align}

How to Represent Negative Numbers? — Two’s Complement

There are different ways of representing negative numbers but there is a method that almost all modern computer systems use: Two’s Complement.

To convert a binary number to its negative (let’s say 0010), we have the following procedure:

  1. Flip all the digits of the number
  2. Add one to the result

By applying these operations to number $(0010)2$ which is $(2){10}$ we find that $-2$ is $(1110)_2$. This representation divides the available bit patterns into two halves: one half represents non-negative numbers, while the other half represents negative numbers. If we use n digits to represent a binary number, we can represent $2^(\text {n} \minus 1) \minus 1$ positive numbers and $2^(\text {n} \minus 1)$ negative numbers.

One of the reasons that this is used most of the time is that the rules for addition works here. If you use two’s complement to represent numbers, you will find 0 when you add a number with its negative.

There is some to note here: Computers perform operations on fixed sized numbers. If an addition produces a carry beyond the most significant bit, that carry is discarded. If the discarded carry changes the mathematical result, an overflow has occurred.

How to Subtract Numbers in Binary System?

Computers perform subtraction operations by simply converting the second operand to its two's complement representation and then add the numbers.

Conclusion

Understanding binary numbers and two’s complement is fundamental to understanding how modern computers perform arithmetic. In future articles, we’ll build on these concepts to explore arithmetic circuits such as the Half Adder, Full Adder, and eventually the Arithmetic Logic Unit (ALU).


메타데이터
post_id
ce03cbd1d78d
slug
understanding-binary-numbers-and-twos-complement-ce03cbd1d78d
url
https://medium.com/@furkaankaraduman/understanding-binary-numbers-and-twos-complement-ce03cbd1d78d
canonical_url
https://medium.com/@furkaankaraduman/understanding-binary-numbers-and-twos-complement-ce03cbd1d78d
author_url
https://medium.com/@furkaankaraduman
status
ok
fetched_at
2026-07-08 23:08:13