Number Bases
From Compsci.ca Wiki
Contents |
Number Bases
In math and computer science, numbers are often taken for granted, but understanding them is absolutely essential. The first thing to understand about numbers is how they're written, and for that we have to understand number bases.
Decimal
The base we're all raised on these days is base 10. We all know that in decimal representation "1" is one, "2" is two" and "456" is four hundred and fifty-six, but how does this actually work? How do we know that that "4" being where it indicate four hundred and how does the 5 being where it is indicate fifty?
In the case opf 456, we can see this as follows.
456 broken down | ||
---|---|---|
4 x 100 | 5 x 10 | 6 x 1 |
Of course, if you know anything about exponents, you should notice that there's a very simple pattern here.
456 broken down further | ||
---|---|---|
4 x 100 | 5 x 10 | 6 x 1 |
4 x 10^{2} | 5 x 10^{1} | 6 x 10^{0} |
We can factor this out further
Factoring out the base | ||
---|---|---|
4 x 100 | 5 x 10 | 6 x 1 |
4 x 10^{2} | 5 x 10^{1} | 6 x 10^{0} |
4 x b^{2} | 5 x b^{1} | 6 x b^{0} |
Now we should be able to extrapolate this pattern out to deal with decimal numbers of any length.
Binary
Binary is a very formal way of saying "base 2." In base 2 the only digits at our disposal for representations are 0 and 1. Let's break down a binary number.
Breakdown of 11001101 | |||||||
---|---|---|---|---|---|---|---|
1 x 128 | 1 x 64 | 0 x 32 | 0 x 16 | 1 x 8 | 1 x 4 | 0 x 2 | 1 x 1 |
1 x 2^{7} | 1 x 2^{6} | 0 x 2^{5} | 0 x 2^{4} | 1 x 2^{3} | 1 x 2^{2} | 0 x 2^{1} | 1 x 2^{0} |
1 x b^{7} | 1 x b^{6} | 0 x b^{5} | 0 x b^{4} | 1 x b^{3} | 1 x b^{2} | 0 x b^{1} | 1 x b^{0} |
Equivalent Decimal Representation | |||||||
128 | 64 | 0 | 0 | 8 | 4 | 0 | 1 |
When we add the decimal equivalents together using the addition we all know quite well, we get 205.
Hexidecimal
Also known as "base 16." Zero to nine are represented as one familiar with decimal would expect, while ten through fifteen are represented by A-F.
Breakdown of A9 | |
---|---|
A x 16 | 9 x 1 |
A x 16^{1} | 9 x 16^{0} |
A x b^{1} | 9 x b^{0} |
Equivalent Decimal Representation | |
160 | 9 |
The Obvious Pattern
The pattern here should be obvious. In number representations each digit represents that amount multipled by the based raised to the position of the digit from the right, starting from zero.