When working with computers, one of the first things we will need is to store integer numbers (and it was needed back in its day as well).
Let’s remember that integer numbers include:
- Positive natural numbers (1, 2, 3…)
- Zero (0, here’s a zero, look how nice it is, all round)
- Negative numbers (-1, -2, -3…)
But as we know, internally our computer only knows about numbers in the binary system. So we will have to see how we can represent our numbers in this system.
For now, in this article we are going to see how to encode positive integers and zero (in the next article we will talk about negative numbers).
Representation of Positive Integers in Binary
The representation of positive integers is the simplest of all. It really isn’t much of a mystery, it’s simply counting upwards (it doesn’t matter if it’s Base 2, Base 10, or Base “whatever”).
But let’s write it down in a few guidelines:
- Zero is zero, in any base
- From there we increment according to the base we are working in
For example, these would be the first 16 positive numbers represented, counting from zero, represented in Decimal and Binary systems:
| Decimal | Binary |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
| 10 | 1010 |
| 11 | 1011 |
| 12 | 1100 |
| 13 | 1101 |
| 14 | 1110 |
| 15 | 1111 |
To switch from one to the other we only have to change the base, as we already saw in this article.
How Much is a Binary Number Worth?
Important, let’s pause for a reflection I will never tire of repeating. Do not confuse a number with its representation.
I repeat it a lot because, if you understand that, you will avoid many problems and errors in understanding all of this
When you see a number in the binary system, for example:
10011001
How much is that set of bits worth? You don’t know, it doesn’t mean anything until you tell me what it is representing.
So, it will be different things if:
- It represents an integer number
- It represents a number with positives and negatives
- It represents a fractional number
- It represents something else…
Of course, if you don’t tell me anything, the logical thing is that I will assume you are referring to a positive number, because it is the simplest one. So the number from before is worth 153, if you don’t tell me anything else.
