eolas/Electronics_and_Hardware/Binary/Binary_number_system.md

109 lines
2.6 KiB
Markdown
Raw Normal View History

2022-04-23 13:26:53 +01:00
---
2022-10-04 10:00:05 +01:00
title: Binary number system
2022-08-20 12:30:04 +01:00
categories:
2022-04-23 13:26:53 +01:00
- Mathematics
2022-08-21 11:00:04 +01:00
- Computer Architecture
2022-09-28 11:00:05 +01:00
tags: [binary, number-systems]
2022-04-23 13:26:53 +01:00
---
2022-08-20 12:30:04 +01:00
2022-10-04 10:00:05 +01:00
# Binary number system
2022-04-23 13:26:53 +01:00
## Decimal (denary) number system
Binary is a **positional number system**, just like the decimal number system. This means that the value of an individual digit is conferred by its position relative to other digits. Another way of expressing this is to say that number systems work on the basis of **place value**.
In the decimal system the columns increase by **powers of 10**. This is because there are ten total integers in the system:
$1, 2, 3, 4, 5, 6, 7, 8, 9$
When we have completed all the possible intervals between $0$ and $9$, we start again in a new column.
2022-09-28 11:00:05 +01:00
The principle of counting in decimal:
2022-04-23 13:26:53 +01:00
2022-09-28 11:00:05 +01:00
```
0009
0010
0011
0012
0013
...
0019
0020
0021
```
2022-05-19 08:40:09 +01:00
2022-04-23 13:26:53 +01:00
Thus each column is ten times larger than the previous column:
2022-09-28 11:00:05 +01:00
- Ten ($10^1$) is ten times larger than one ($10^0$)
- A hundred ($10^2$) is ten times larger than ten ($10^1$)
2022-04-23 13:26:53 +01:00
We use this knowledge of the exponents of the base of 10 to read integers that contain multiple digits (i.e. any number greater than 9).
Thus 264 is the sum of
2022-09-28 11:00:05 +01:00
$$[4 \cdot (10^0)] + [6 \cdot (10^1)] + [2 \cdot 10^2] $$
2022-04-23 13:26:53 +01:00
## Binary number system
In the binary number system, the columns increase by powers of two. This is because there are only two integers: 0 and 1. As a result, you are required to begin a new column every time you complete an interval from 0 to 1.
So instead of:
$$ 10^0, 10^1, 10^2, 10^3 ... (1, 10, 100, 1000) $$
You have:
$$ 2^0, 2^1, 2^2, 2^3, 2^4... (0, 2, 4, 8, 16) $$
When counting in binary, we put zeros as placeholders in the columns we have not yet filled. This helps to indicate when we need to begin a new column. Thus the counting sequence:
$$ 1, 2, 3, 4 $$
is equal to:
$$ 0001, 0010, 0011, 0100 $$
Counting in binary:
2022-09-28 11:00:05 +01:00
```
000000
000001
000010
000011
000100
000101
000111
```
2022-04-23 13:26:53 +01:00
2022-10-06 11:30:05 +01:00
## Binary prefix
2022-12-10 12:30:10 +00:00
To distinguish numbers in binary from decimal or [hexadecimal](/Electronics_and_Hardware/Binary/Hexadecimal_number_system.md) numbers, it is common to use the prefix `0b`. Thus, e.g, `0b110` for decimal `6`.
2022-10-06 11:30:05 +01:00
2022-09-28 11:00:05 +01:00
## Converting decimal to binary
2022-04-23 13:26:53 +01:00
2022-09-28 11:00:05 +01:00
Let's convert 6 into binary:
2022-04-23 13:26:53 +01:00
If we have before us the binary place values ($1, 2, 4, 8$). We know that 6 is equal to: **1 in the two column and 1 in the 4 column → 110**
More clearly:
2022-05-19 08:40:09 +01:00
![](../../_img/Pasted_image_20220319135558.png)
2022-04-23 13:26:53 +01:00
And for comparison:
2022-05-19 08:40:09 +01:00
![](../../_img/Pasted_image_20220319135805.png)
2022-04-23 13:26:53 +01:00
Or we can express the binary as:
2022-09-28 11:00:05 +01:00
$$ (1 _ 2) + (1 _ 4) $$
2022-04-23 13:26:53 +01:00
Or more concisely as:
$$ 2^1 + 2^2 $$
### Another example
Let's convert 23 into binary:
![](../../_img/Pasted_image_20220319135823.png)