# Number Systems

##### Dale Swanson 11-11-2007 We all grew up using a number system that has 10 digits. However, there are other number systems with any number of digits you want. To understand how these work we'll look at how our normal system works. But, before that we need to clear up the terms:

Digit
A digit is a symbol the represents a number, note that there are only 10 digits in our number system, and we combine them to make numbers. A digit is comparable to a letter, and a number is comparable to a word (note a single letter can be a word, just like a single digit can be a number).
Base X
When dealing with number systems we say base to mean how many digits a system uses. Our normal system uses 10 and is thus base 10.
Decimal
This is the normal number system we use day in and day out, it has 10 digits and thus is base 10. Dec is some Roman root for 10, and thus the name (along with decade).
Binary
This is maybe the most commonly heard other number system, base 2 (root of bi). It's very easy to represent since you only need two digits, you can use just about anything to store numbers as binary, which is why computers use binary.
Octal
This is base 8, and the only reason it gets used is because 8 is a power of 2, and binary is base 2. It's easy to convert numbers from one base to another if the bases are powers of each other.
Usually called hex, it's base 16 (hex is 6 + decimal for 10 = 16). This is probably the most commonly used number system other than decimal. Again since 16 is a power of 2 (24) it's easy to convert numbers from binary to hex and back. Almost no one works with real binary, rather they work with hex representing binary.

### Decimal

We have 10 digits, 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, and with those we can make any number we want. When we count we start at 0, then we go up by one to 1, then another one up to 2, again to 3, and so on until 9. At nine we have a problem, we've run out of digits, so what do we do? We add a 1 to the left and go back to 0, giving us 10. This is obvious to us since we've been using it for life, but you need to really understand what's going to to grasp how other number systems work. You may remember that there are an infinite number of 0's to the left of every number (and also to the right after the decimal place), we don't usually write these out because writing an infinite number of 0's gets old fast. You can write any number of 0's less than infinity and it is still the same number (there are still infinite more 0's assumed to the left of the 0's you write). So the number 138 = 0138 = 00000138. Back to counting we really start out with 000, then 001, then 002 ... 009 then it's easy to see why a one pops up next to the nine, since there was a zero there all along, and the next digit after zero is one. So now we have 010, then 011, 012 ... 019, then again we just rollover the one to a two, and reset the nine to zero, giving us 020, then 021 ... up to 099. You can probably guess that this is no different than just 009, in that the zero is going to go up to one and the nines are going to reset to zeros, giving us 100, then 101, etc. So now you probably understand better how counting actually works. Let's see what happens in another base.

### Base 9

No one uses base nine, for anything useful, but since it's just one less than our system I'll use it to break in the concept. Now the first confusing thing about bases is that the highest digit is one less than the base you are in. In base 10 the highest digit is 9, not 10, there is no digit for 10 (it's a combo of two digits). This is because the first digit is always zero, the second digit is one, you can see how we are one higher in the digit count than what number the digit represents. In base 10 this seems obvious since we are used to it, but in base 9 it means that the highest digit is eight, not nine (if it were nine it'd be no different than base 10). So let's see what happens when we count in base 9, like we did above in base 10. Start with 000, then 001, then 002, it's the same up to 008. Now we have a problem, we've run out of digits (remember the digit 9 doesn't exist in base 9). However, this is no different than when we ran out of digits in base 10. What did we do there? We rolled over the zero to a one, and reset the nine to zero. We'll do the same here (except we reset the eight). Thus the next number after 008 is 010. The numbers continue as before 011, 012 ... 018, again we don't have a nine, so we just rollover giving 020, this pattern continues up to 088, now we have to roll over that zero to one and we have 100, then 101...etc. Counting in different bases is actually pretty easy, you just have to make a conscience effort not to use the digits that don't exist. As for how to read the numbers, the convention is to say each digit separately, and if it hasn't been established say the base you are in. To read the number 047 in base 9 you'd say "zero four seven, base nine". If you said "forty seven, base nine" it would be assumed you meant the number 47 (in base 10) in base 9, which is 52. That last part may be confusing, and that's because converting between bases is confusing. For now lets just stick to counting in the bases.

### Binary

Binary is base 2, and as I said above binary is wonderful because it only needs two symbols, and thus is very easy to represent. For instance you could store a number in binary with just dots and blanks, or dots and dashes, or horizontal and vertical lines (| and -). In the real world you could store it using anything that could be measured by setting a barrier, and saying anything below it is one thing, and anything over is the other. For example you could use the length of sticks, and say any stick over a foot in length is one digit, and the other digit is any stick shorter than a foot. In computers binary is stored using measures of electricity and magnetism.

So let's count in binary. We start as always with 000. We go up by one to 001, however we already have a problem, as 0 and 1 are our only digits (base 2 only has two digits, remember the number of the base is never a digit in that base, thus 2 isn't a digit in base 2). Since we have no other way to continue we must rollover the zero, giving us 010. Now we continue, 011, but again we run out of digits, so we must rollover both ones, giving 100, then 101, then (rollover again) 110, and 111. That's all the number we can represent with three digits in binary. To continue we must rollover one of the assumed zeros to the left to get 1000, then 1001, and so on. Binary is much easier to understand if you see it in a chart which I have below.

Hexadecimal is base 16, and like I said above hex is used because it's easy to convert from binary to hex. Binary is annoying to use because it takes so many digits to represent numbers (for example the number 138 in decimal is 10001010 in binary). The higher the base the less digits you need to represent a number. Let's count in hex. Start with 000, 001, 002...009, now we have a real problem, since we have sixteen digits in hex we can't rollover to 010 yet. But, what do we use after nine to represent that digit. There are no rules, you could use anything, but by far the convention is the start using letters. So after 009 we have 00a. There are no absolute rules about this but almost always a follows right after 9 (and a or A can be used interchangeably), then the letters continue in normal order for however long you need. So we are at 00a, then 00b, 00c, 00d, 00e, 00f. F is our last digit (digit sixteen), so we must rollover to 010. Then we continue as always 011, 012... 019, 01a, 01b... 01f, (rollover) 020, 021... 0ff (rollover) 100. Again this is easier to understand when it's laid out in a chart, don't worry the chart is coming.

### Base-26

Base 26 isn't really used much, however, it does have one obvious quality. It has the same number of digits as letters in the alphabet. Normally with a number system we start with zero, then use letters when we use all the normal digits. With base 26 though, I like to use only letters. 0 is a, 1 is b, and so on. This can be a bit confusing, since we aren't used to seeing a's as zeros. Thus there are an infinite amount of a's to the left of the number. To count we start with aaa (which is the same as a or aaaaaa, it's all zero), then go to aab, aac, aad, and so on. When we get to aaz we rollover to aba just as you'd expect. Since base 26 isn't really used how you represent the digits depends on the context, you can use all letters or the number letter combo like in hex. Although I don't see why you'd be using base 26 except to be able to encode your numbers as pure letters.

### Base-36

If you want to use letters and numbers then base 36 is a much better choice. Base 36 uses the digits 0-9 then the letters a-z for it's digits. To count you start with 000, 001...009, 00a, 00b...00z, 010, 011...019, 01a, 01b...01z, 020. There's not much more to say about base 36, if you understood the other bases you should understand base 36.

### Base-64

Base 64 is the highest base I've ever seen used at all. It has two qualities that make it useful. First, it's a power of 2, like octal or hex, meaning it's easy to convert from binary to it. Second, it uses all the letters, lower and upper case, plus all the digits, and then 2 other symbols. What the other 2 symbols are isn't really agreed upon, and really it doesn't matter. I like to use space and period, since they are the two most common none letter or digit characters you'd find in normal text. Using space can cause problems though, as multiple spaces next to each other can be quite hard to read. So in the chart below I used slash / instead. To count in base 64 we start with 000, 001...009, 00A, 00B...00Z, 00a, 00b...00z, 00/, 00., 010, 011. Again there's no real standard as to which is greater A or a, so just use whatever.

### Bits and Bytes

Bits and bytes aren't a number system, so why am I bringing them up? Because computers store everything using them, and thus they go hand in hand with binary and hex. A bit is a binary digit. A bit is a single digit in binary, a 1 or 0, yes or no, true or false, positive or negative. It's the smallest amount of info you can store. There are eight bits in a byte. When you write out a byte in binary you write out 8 zeros or ones, usually you put a space between groups of eight. The number 138 in binary would be 10001010, that would be one byte. Since a byte is eight base two digits it can store any number up to 28 = 256. This is the same for any number system, the highest number you can represent with d digits in base b is bd. So with 5 digits in decimal you can store 105 = 100,000 different numbers. A note here is that since you have to represent zero you can only represent up to 99,999 with five digits, although there are 100,000 numbers from 0-99,999 (count them, I'll wait).

Ok, welcome back. So now we know that a byte is eight ones or zeros called bits. A byte can represent any number from 0-255 (if you really want to be confused a byte could be considered a base 256 number). Everything on a computer is converted to numbers and then stored as a series of numbers. Text for example is stored using a standard called ASCII, in which each character (letter) is one byte (eight bits). A capital X for example is stored as the number 88 (in base 10) which is 01011000 in binary. As I said above dealing with binary becomes annoying due to its size. This is why hex is used. A single hex digit can represent four binary digits. Thus two hex digits can represent eight binary digits, and what else is eight binary digits? A byte, right. You can test this by opening up notepad typing a single letter then saving it and checking the file size. It's will be one byte. So our capital X in hex is 58. 58 is much easier to work with than 01011000, and unlike 88 (which is the decimal form of it), you can still easily convert from 58 to binary. To see what numbers represent all the letters you can look up an ASCII Chart.

I keep saying hex is easy to convert to binary, but you probably aren't convinced. Like I said a single hex digit can represent four bits (binary digit). For example E is 1110. Two hex digits represents eight bits, example E3 is 1110 0011. I spaced that binary number into two groups of four to show that the E still becomes 1110 just like it did when it was by itself, and 3 becomes 0011. No matter how many hex digits are around hex E it will always become binary 1110. Going from binary to hex the reverse is true, 1110 will always become E in hex. If you don't have a multiple of four number of bits then you just add zeros to the left (remember there are infinite zeros to the left) until you do.

Since a byte is eight bits, and eight bits is two hex digits you usually see hex in two digit pairs, which represent bytes. As an example the ASCII version of Monkey in hex would be 4D 6F 6E 6B 65 79. Each two hex digit pair represents one character, which is one byte, and eight bits. Another common use of hex is to represent colors. If you've done any html or photo editing, you've probably seen six alphanumeric codes that represent colors. These are just three hex pairs. Each pair represents a number from 0-255 and that represents how bright a color is. Any color can be made by combining three colors (the three are different for light and pigments, for light they are red, green, blue, for pigments it's red, blue, yellow, or technically magenta, cyan, yellow). If you get really close to a TV you can see that there are a bunch of little squares made up of those three colors. By displaying different levels of brightness from each of those a TV (or a monitor) can make any color it wants. Each of those squares is called a pixel. When you see those six digit codes what are are seeing is the level of brightness of red, green, and blue on a scale from 0-255, or 00-FF in hex. Thus 00FF00 is pure green (255 level brightness green, 0 brightness for blue and red). All the colors maxed out make white (FFFFFF), and all of them at zero make black (000000).

Well I think I've explained this pretty thoroughly now. You should grasp how the number systems work, and why hex is commonly used when dealing with computers. If you are still foggy here is the promised chart:

 Name Decimal Binary Octal Hexadecimal Base-26 Base-26 Base-36 Base-64 Roman Base 10 2 8 16 26 26 36 64 zero 0 00000000 0000 00 00 AA 00 00 one 1 00000001 0001 01 01 AB 01 01 I two 2 00000010 0002 02 02 AC 02 02 II three 3 00000011 0003 03 03 AD 03 03 III four 4 00000100 0004 04 04 AE 04 04 IV five 5 00000101 0005 05 05 AF 05 05 V six 6 00000110 0006 06 06 AG 06 06 VI seven 7 00000111 0007 07 07 AH 07 07 VII eight 8 00001000 0010 08 08 AI 08 08 VIII nine 9 00001001 0011 09 09 AJ 09 09 IX ten 10 00001010 0012 0A 0A AK 0A 0A X eleven 11 00001011 0013 0B 0B AL 0B 0B XI twelve 12 00001100 0014 0C 0C AM 0C 0C XII thirteen 13 00001101 0015 0D 0D AN 0D 0D XIII fourteen 14 00001110 0016 0E 0E AO 0E 0E XIV fifteen 15 00001111 0017 0F 0F AP 0F 0F XV sixteen 16 00010000 0020 10 0G AQ 0G 0G XVI seventeen 17 00010001 0021 11 0H AR 0H 0H XVII eighteen 18 00010010 0022 12 0I AS 0I 0I XVIII nineteen 19 00010011 0023 13 0J AT 0J 0J XIX twenty 20 00010100 0024 14 0K AU 0K 0K XX twenty one 21 00010101 0025 15 0L AV 0L 0L XXI twenty five 25 00011001 0031 19 0P AZ 0P 0P XXV twenty six 26 00011010 0032 1A 10 BA 0Q 0Q XXVI twenty seven 27 00011011 0033 1B 11 BB 0R 0R XXVII twenty eight 28 00011100 0034 1C 12 BC 0S 0S XXVIII thirty five 35 00100011 0043 23 19 BJ 0Z 0Z XXXV thirty six 36 00100100 0044 24 1A BK 10 0a XXXVI thirty seven 37 00100101 0045 25 1B BL 11 0b XXXVII thirty eight 38 00100110 0046 26 1C BM 12 0c XXXVIII sixty one 61 00111101 0075 3D 29 CJ 1P 0z LXI sixty two 62 00111110 0076 3E 2A CK 1Q 0/ LXII sixty three 63 00111111 0077 3F 2B CL 1R 0. LXIII sixty four 64 01000000 0100 40 2C CM 1S 10 LXIV sixty five 65 01000001 0101 41 2D CN 1T 11 LXV sixty six 66 01000010 0102 42 2E CO 1U 12 LXVI one hundred twenty six 126 01111110 0176 7E 4M DW 3I 1/ CXXVI one hundred twenty seven 127 01111111 0177 7F 4N DX 3J 1. CXXVII one hundred twenty eight 128 10000000 0200 80 4O DY 3K 20 CXXVIII one hundred twenty nine 129 10000001 0201 81 4P DZ 3L 21 CXXIX one hundred thirty 130 10000010 0202 82 50 EA 3M 22 CXXX two hundred fifty four 254 11111110 0376 FE 9K JU 72 3/ CCLIV two hundred fifty five 255 11111111 0377 FF 9L JV 73 3. CCLV two hundred fifty six 256 100000000 400 100 9M JW 74 40 CCLVI one thousand 1,000 1111101000 1750 3E8 1CC BMM RS Fe M two thousand, five hundred 2,500 10111011100 4704 9C4 3I4 CSD 1XG d4 MMD five thousand 5,000 1001110001000 11610 1388 7A8 HKI 3UW 1E8 V sixteen thousand, three hundred eighty three 16,383 11111111111111 37777 3FFF O63 YFC CN3 3.. XVMCCCLXXXIII sixteen thousand, three hundred eighty four 16,384 100000000000000 40000 4000 O64 YFD CN4 400 XVMCCCLXXXIV seventeen thousand, four hundred fifty seven 17,457 100010000110001 42061 4431 PLB ZVL DGX 4Gn XVMMCDLVII thirty two thousand, seven hundred sixty seven 32,767 111111111111111 77777 7FFF 1MC7 BWMH PA7 7.. XXXMMDCCLXVII thirty two thousand, seven hundred sixty eight 32,768 1000000000000000 100000 8000 1MC8 BWMI PA8 800 XXXMMDCCLXVIII sixty five thousand, five hundred thirty five 65,535 1111111111111111 177777 FFFF 3IOF DSAP 1EKF F.. LXVDXXXV sixty five thousand, five hundred thirty six 65,536 10000000000000000 200000 10000 3IOG DSAQ 1EKG G00 LXVDXXXVI four billion, two hundred ninety four million, nine hundred sixty seven thousand, two hundred ninety five 4,294,967,295 11111111111111111111111111111111 37777777777 FFFFFFFF DNCHBNL NXMRLXV 1Z141Z3 3..... four billion, two hundred ninety four million, nine hundred sixty seven thousand, two hundred ninety six 4,294,967,296 100000000000000000000000000000000 40000000000 100000000 DNCHBNM NXMRLXW 1Z141Z4 400000