Language: EN

representar-numeros-positivos-en-binario

How to represent positive integers in binary

When we work with computers, one of the first things that we are going to need (and was needed at the time) is to store integer numbers.

Let’s remember that integer numbers are the positive natural numbers (1, 2, 3…), zero (0, here’s a zero, look how cute and round it is), and negative numbers (-1, -2, -3…).

But as we know, internally our computer only knows about numbers in binary system. So we will have to see how we can represent our numbers in this system.

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, whether it’s Base 2, Base 10, or Base “whatever”.

But let’s write it in some guidelines:

  • Zero is zero, in any base
  • From there, we increment according to the base in which we work

For example, these are the first 16 positive numbers represented, including zero, represented in Decimal and Binary systems:

DecimalBinary
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
101010
111011
121100
131101
141110
151111

To switch from one to the other, we only have to change the base, as we saw in this article.

How much is a binary number worth?

Important, stop and reflect on something that I’m not going to tire of repeating. Do not confuse a number with its representation.

When you see a number in 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’s representing.

Thus, it will be different things if:

  • It represents an integer number
  • It represents a number with positive and negative values
  • It represents a fractional number
  • It represents something else…

However, if you don’t tell me anything, it’s logical to assume that you are referring to a positive number, because it is the simplest. So, the number from before is worth 153, if you don’t tell me anything else.