User Tools

Site Tools


haas:fall2020:common:helpances:binaryoctaldecimalhex

The value of binary, octal, and hex in computing

Why different number bases?

First, we need to establish the distinction and importance of number bases.

Like units applied to values in varying forms of measurement (distance, length, quantity, volume, etc.), the number base being used to represent values carries some significance.

A number base, at its core, merely indicates how many unique symbols are present for denoting/counting numbers.

In everyday life today, base 10 seems to be the predominant number base used in general practice. But just because that is what we and our modern day civilization transact in, doesn't mean that decimal is the absolute best (indeed, there are various transactions it is notably less effective at), merely what is most commonly expressed (and assumed, if no other identification is provided with a given number).

Past civilizations utilized other number bases, remnants of that influence still survive to this day (the Sumerian use of bases 12 and 60, for example, especially in relation to time).

Computing aside, there are some real practical advantages to bases like 12 (or 60) over 10.

For one: 12 has more factors than 10, so it is far easier to carve out even divisions:

10 = { 1, 2, 5, 10 }
12 = { 1, 2, 3, 4, 6, 12 }

Think of some of the common divisions we seek to regularly apply to our numbers (in base 10): halves, thirds, quarters, eighths.

In base 10, that means:

  • half: /2 (0.500) - which for even numbers poses little difficulty:
    • 10/2 = 5
    • 12/2 = 6
    • 16/2 = 8
    • 23/2 = 11.5
  • third: /3 (0.333) - aside from multiples of 3, tends to be very messy
    • 10/3 = 3.33
    • 12/3 = 4
    • 16/3 = 5.33
    • 23/3 = 7.66
  • quarter: /4 (0.250) - cleaner than a third, but still, outside of multiples of 4, can be messy
    • 10/4 = 2.5
    • 12/4 = 3
    • 16/4 = 4
    • 23/4 = 5.75
  • eighth: /8 (0.125) - like quarters, cleaner than thirds, but still messy
    • 10/8 = 1,25
    • 12/8 = 1.5
    • 16/8 = 2
    • 23/8 = 2.875

In base 12, that means:

  • half: an even base, like decimal, so quite similar
    • 10/2 = 6
    • 12/2 = 7
    • 16/2 = 9
    • 23/2 = 11.6
  • third: with 3 being a factor, things are cleaner for round values
    • 10/3 = 4
    • 12/3 = 4.7B
    • 16/3 = 6
    • 23/3 = 9
  • quarter: 4 is also a factor, so things are cleaner
    • 10/4 = 3
    • 12/4 = 3.6
    • 16/4 = 4.6
    • 23/4 = 6.9
  • eighth: like in decimal, 8 is not a factor, so it gets messier if not a multiple of 8
    • 10/8 = 1.6
    • 12/8 = 1.9
    • 16/8 = 2.3
    • 23/8 = 3.46

Even in the samples above, look at how cleaner thirds are for base 12 than base 10. Simply due to 12 having more factors than 10.

In computing-related endeavours, there is a strong relationship with the usage of base 2, which has but 2 counting values- 0 and 1.

This was done due to the nature of the switch, allowing for a distinctly OFF and ON state. It would have been impractical to use base 10 in this sense, because 8 of the numbers would effectively be useless, resulting in incoherent values.

Look at an example side to side, binary and decimal:

  • binary: 11111111
  • decimal: 255

Sure, we can “memorize” that 255 is the equivalent of 11111111 in binary, but that also removes all the valuable information representing the data in binary offers us.

With but 2 total possibilities for the state (0, or 1), we can clearly see in 11111111 eight total switch states, something that “255” doesn't cleanly allow us to see.

So: because the computer is a binary device, it makes sense to use base 2 to transact numbers and information with it.

Powers of 2

Why, then, are base 8 and 16 also frequently used with computer information?

That has to do with the mathematical concept of exponents (powers), of a base.

base 2, for instance: 2. What happens when we raise it to various exponents?

  • 2^0 = 1
  • 2^1 = 2
  • 2^2 = 4
  • 2^3 = 8
  • 2^4 = 16

This is where we get our “powers of two” from. But moreso, notice how both 8 and 16 are both powers of 2?

This is where the application of octal (base 8) and hexadecimal (base 16) come in.

Because 8 is 2^3, and 16 is 2^4, it can be said that:

  • it takes 3 binary bits to represent 1 octal symbol
  • it takes 4 binary bits to represent 1 hexadecimal symbol

And the same in the reverse direction:

  • 1 octal symbol corresponds with 3 binary bits
  • 1 hexadecimal symbol corresponds with 4 binary bits

There is no rounding error, no remainder, no decimal places: a CLEAN whole value.

Take a look at this table of values:

base 2 base 8 base 10 base 16
0000 00 0 0x0
0001 01 1 0x1
0010 02 2 0x2
0011 03 3 0x3
0100 04 4 0x4
0101 05 5 0x5
0110 06 6 0x6
0111 07 7 0x7
1000 010 8 0x8
1001 011 9 0x9
1010 012 10 0xA
1011 013 11 0xB
1100 014 12 0xC
1101 015 13 0xD
1110 016 14 0xE
1111 017 15 0xF

So, if we had a binary value of 101101110010 (12 binary bits), we can directly and easily “convert” it from binary to octal or decimal (from the right and working left, group together the pertinent number of bits).

  • to base 8: 101101110010 = 101 101 110 010 = 5 5 6 2 = 05562
  • to base 16: 101101110010 = 1011 0111 0010 = B 7 2 = 0xB72

Likewise, in the opposite direction:

  • to base 2: 031337 = 3 1 3 3 7 = 011 001 011 011 111 = 011001011011111
  • to base 2: 0xDEADBEEF = D E A D B E E F = 1101 1110 1010 1101 1011 1110 1110 1111 = 11011110101011011011111011101111

It is THAT EASY to transition between exponent bases of the baseline base. We can work this trick in base 4, base 32, base 64, etc.

It is NOT POSSIBLE to use this trick with bases that do NOT fall in a power of 2. 10, for instance.

There is no whole number for x where 2^x=10, so we have to resort to math. This is why decimal is NOT a good medium for expressing binary values.

Notice how LARGE the binary value gets compared to the higher base:

  • 011001011011111 or 031337
  • 11011110101011011011111011101111 or 0xDEADBEEF
  • 101101110010 or 05562 or 0xB72

The higher the base, the SMALLER (in length) the resulting number will be.

We use base 8 and base 16 as a direct but convenient short-hand to allow us to express binary values, so we don't have to personally transact in each individual bit (yet can retain that necessary awareness of the bits). Again: NOT so convenient using decimal.

haas/fall2020/common/helpances/binaryoctaldecimalhex.txt · Last modified: 2020/10/28 08:32 by wedge