Bases

From Armagetron

If you want to learn about bases, there is a good chance you want to for colors (0xRRGGBB). If you read this, I'll try to explain bases, so that you can use any. I'll start out with regular decimals, then explain base 8 (Oct), 16 (Hex) and binary (base 2). This tutorial is pretty thorough, but you should learn the CONCEPT of bases, so you can use any base.


Decimal

Decimal is the base 10 system people use almost everywhere. It's how we normally count numbers. The ten symbols used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

Whenever you write a number you are actually assigning a VALUE to a set of SYMBOLs, but this is so habitual you don't really realize it. It sounds more complicated than it really is ;)

I'll write it like so Value: Symbol. So "Five: 5" means that the VALUE Five is assigned to the SYMBOL 5.

Decimal system follows this scheme

Zero: 0
One : 1
Two : 2
...
Eight: 8
Nine : 9

I'm sure this looks familiar :) Now, as you can see, after ten values (Zero - Nine) we're out of symbols (0-9). *Gasp* What to do? We add a place like this

Ten: 10

Note that I'm not using a new symbol! I'm not doing Ten: þ or anything, I'm recycling old symbols. I just add a 1 to the beginning and start over. You could have put a zero infront of the first batch (Zero: 00, One: 01...). Now that you've used up all symbols you start over with a 1.

Eleven: 11
Twelve: 12
...
Eighteen: 18
Nineteen: 19

Notice how we're going through the 0-9 again, just with a different number in front of it? Good. As we are out of symbols again we must increase the leading 1:

Twenty: 20
Twentyone: 21
Twentytwo: 22
...
Twentynine: 29

As we are out of symbols yet again we shift the 2 to 3, This gets us Thirty - Thirtynine. You can keep repeating this process to get all numbers below hundred, but then:

Ninetyeight: 98
Ninetynine:  99

We're out of symbols again. This time, however, we're out of leading symbols as well! *Double Gasp* What to do? We add another space.

Ninetynine: 099
Hundred: 100

Now we can continue for another hundred. Better yet, when those are over we don't have to add a space yet, we can increase the new 1.

I hope you understood all this. If you can count (I hope you can) then you already knew this but you may not have realized you were doing it. This is not a problem for Decimals, they are so common we can do them without thinking. When we use other bases, however we need to start realizing what we are doing. Read this section untill you understand, exactly, why we can count to any number with just ten symbols, and why it takes longer and longer to add a new space.

Octal

Octal is base 8. You won't see it nearly as much as hex and bin, but it's easiest to learn using other bases with a base that's greater than two and lower than ten. Octal uses 8 symbols (hence base 8): 0, 1, 2, 3, 4, 5, 6, 7.

Zero: 0
One: 1
Two: 2
...
Six: 6
Seven: 7

Out of symbols! We add a new space:

Seven: 07
Eight: 10
Nine: 11
Ten: 12
...
Fourteen: 16
Fifteen: 17

Out of symbols, so we increase the leading 1:

Sixteen: 20
Seventeen: 21
...

You can continue doing this, like with decimals, forever.

Note that the names for values are based on the decimal system. For example:

  • Sixteen: six + ten = 6 + 10 in decimal
  • Fourty-five: four * ten + five = 4 * 10 + 5 in decimal
  • Eighty-three: eight * ten + three = 8 * 10 + 3 in decimal

In other bases that simple relation breaks apart. Don't let that confuse you.

If you understand this, move on to hex.


Hexadecimal

Base 16. This one follows the same rules as the others:

Zero: 0
One: 1
Two: 2
...
Nine: 9

Now, what symbol should we use? base 16 obiously has 16 symbols, but our decimal only has ten. So we use letters: A, B, C, D, E, F (note: Armagetron uses the small letters a-f for foreground and the capitals A-F for background. With mixed case it ignores the capitals. I will use capitals here. Just remember to use small letters in Armagetron).

Ten: A
Eleven: B
...
Fourteen: E
Fifteen: F


Out of symbols so:

Sixteen: 10
Seventeen: 11
...
Thirty: 1E
Thirtyone: 1F

SYMBOLS KAPUT

Thirtytwo: 20
Thirtythree: 21

etc. For Armagetron you use up to FF, 255 decimal. This is equivalent to one byte, the smallest common unit of computer memory.

Binary

Binary uses only two symbols: 0, 1. As you probably know, computers use binary.

Zero: 0
One: 1

We're out of symbols already so we must add a space.

One: 01
Two: 10
Three : 11

Again, out of symbols. Since binary uses so few symbols I'll not break it up anymore. I'm sure you can find where I add new symbols.

Three: 011
Four: 100
Five: 101
Six: 110
Seven 111
Eight: 1000
Nine: 1001
Ten: 1010
...