- What are number bases?
- Why do we use different number bases in computer programming?
What are number bases?
A number base is a mathematical term which explains how to interpret a series of digits, as a numerical value.
Most of us will have been taught to use a base 10 numbering system, although you may not be aware of this. A base 10 numbering system means that each single digit will represent one of 10 possible values (0-9).
In school you probably learned that any number – let's take 2147 – can be broken down into columns to show that it is equal to 2x1000 + 1x100 + 4x10 + 7x1. These columns represent the orders of magnitude of our base number. The units column represents our base number of 10, with an exponent of 0. Our tens column represents our base number of 10 with an exponent of 1. This is shown in the table below.
Why do we use number bases in computer programming?
Put simply, a computer is a box full of complicated electronics. Fortunately only a very basic understanding is needed for computer programming. Where appropriate we will be demonstating basic principles using simple electronics circuits in order to give an easy to understand visual representation.
In the illustration above we can see that the circuit can only be in one of two states. When the switch is closed the lamp is on, and when the switch is open the lamp is off. In computer science we count these states as 0 representing off and 1 representing on.
Above we have modified the circuit by entering another switch and lamp, now we have a total of 4 different states. We have counted and displayed these states in the table below.
|State count||Lamp 1 state||Lamp 0 state|
|0||0 (off)||0 (off)|
|1||0 (off)||1 (on)|
|2||1 (on)||0 (off)|
|3||1 (on)||1 (on)|
Due to the two basic states of a digital circuit this lends itself to representation in base 2, with each digit representing a single wire state of off or on (0 or 1 respectively). If we want to represent multiple wires then we can simply add an additional column to our number. Below is a table showing how 4 wires would be represented in base 10 (decimal) and base 2 (binary).
|Decimal Value||Binary Value||Wire 3||Wire 2||Wire 1||Wire 0|