The address for this web page is:   `http://fishcaro.crosswinds.net/day_25_number_systems_nse.htm`
On to the next lesson!
Back to the COURSE SYLLABUS

# 25. NUMBER SYSTEMS

The time has come to discuss COLORS on the web. Here's how we'll proceed:
• First, we'll talk about representing NUMBERS on computers (and on the web, in particular). This is today's lesson.
• Next, we'll talk about using numbers to represent COLORS on the web.
• Then, we'll talk about "WEB-SAFE" colors.
These are the topics for the next three lessons. You'll need 3 index cards (6 sides) for today's lesson.

INDEX CARDS #25:

## THE DECIMAL NUMBER SYSTEM (25a)

The need to COUNT emerged a long, long time ago. Since humans have ten fingers, it was very natural to count in groups of ten: count out ten things, bundle these up into a pile of ten, and then start over.
Any time you have ten of anything, it gets bundled up into a bigger pile.
Got ten piles of 10? Bundle them up into a pile of one hundred.
Got ten piles of hundreds? Bundle them up into a pile of one thousand. And so on.
Hence the origin of our DECIMAL (base ten) number system.
In the base TEN number system, TEN distinct digits are used: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. These ten digits are used to represent any number. The position of each digit determines its contribution.
For example, the decimal number "364" (read as "three hundred sixty-four") represents 3 hundreds, 6 tens, and 4 ones:
364 = 3×102 + 6×101 + 4×1

## THE BINARY NUMBER SYSTEM (25b)

COMPUTERS don't have ten fingers, so the decimal system isn't appropriate. Instead, due to the electrical nature of computers, a base two system makes more sense: either current is flowing (ON) or not (OFF). There are only two "states". So, at the lowest level, everything on computers is done in base two, called the BINARY number system. In the base two system, things are bundled up in piles of 2:
Got two piles of 2? Bundle them up into a pile of 4.
Got two piles of 4? Bundle them up into a pile of 8.
Continuing in this way, we get piles of sizes: 21=2, 22=4, 23=8, 24=16, 25=32, 26=64, 27=128, 28=256, and so on. In the base TWO number system, TWO distinct digits are used: 0 and 1 . These two digits are used to represent any number. The position of each digit determines its contribution.
For example, 364 objects can be bundled up into: 1 pile of 256, 1 pile of 64, 1 pile of 32, 1 pile of 8, and 1 pile of 4. Hence, the binary representation of 364 is:
``````364 = 1×256 + 0×128 + 1×64 + 1×32 + 0×16 + 1×8 + 1×4 + 0×2 + 0×1
= 1×28  + 0×27  + 1×26  + 1×25 + 0×24 + 1×23 + 1×22 + 0×21 + 0×1
= 101101100 (base two)
``````

## READING NUMBERS IN OTHER BASES (25c)

How should I read and write the binary number "101101100"? Just say each digit aloud, followed by "base two," like this: one, zero, one, one, zero, one, one, zero, zero, base two.
DON'T put commas into the number: "101,101,100"  and DON'T READ IT AS "one hundred one million, one hundred one thousand, one hundred." These conventions are reserved for decimal numbers, and this isn't a decimal number.

You can express any number in any base that you'd like: just group accordingly.

Numbers expressed in base two can get VERY LONG. You already saw how long the name for 364 is: 364 (base ten) = 101101100 (base two). This gets rather tedious.

When you have a number expressed in base two, you already have information about "piles" of sizes 8 and 16. So, it's easy to convert from base two (binary) to base eight (OCTAL) and base sixteen (HEXADEMICAL). Consequently, the octal and hexadecimal systems are frequently used in connection with computers.

## SPECIAL SYMBOLS FOR BASE SIXTEEN (25d)

The base SIXTEEN number system is called the HEXADECIMAL system. It is used extensively on the web (for representing special symbols, colors, and so on).
HEX=6 (think "hexagon"); DECIMAL=10; 6 + 10 = 16. So, hexadecimal seems an appropriate name.
In the base SIXTEEN number system, SIXTEEN distinct "digits" are required. This poses a bit of a problem, since only ten are readily available: 0 through 9. This leaves us needing six additional "digits." Here's what was chosen:
```A    is used to represent ten;
B    is used to represent eleven;
C    is used to represent twelve;
D    is used to represent thirteen;
E    is used to represent fourteen;
F    is used to represent fifteen.
```
These sixteen symbols (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) can now be used to represent any number. The position of each symbol determines its contribution.

In base sixteen, we get piles of sizes: 161=16, 162=256, 163=4096, and so on.

For example, 364 objects can be bundled up into: 1 pile of 256, 6 piles of 16, and twelve ones. Hence, the hexadecimal representation of 364 is:

``````364 = 1×256 + 6×16 + 12×1
= 1×162 + 6×161 + 12×1
= 16C (base sixteen)
``````
Read this as: "one six C, base sixteen" or "hexadecimal; one six C."

How do I know when I'm being given a hexadecimal number? Hexadecimal numbers used in HTML are preceded with the symbol "#".
Thus, the number "#16C" means "one six C, base sixteen."
The number "#236" means "two three six, base sixteen."

## BINARY TO HEXADECIMAL and more (25f)

It's very easy to convert from binary to octal or from binary to hexadecimal. Think about WHY these techniques work!
To convert from binary to octal, use the "group by threes" technique. For example,
```10111101 (base two)
= 010 111 101 (break into groups of three; add leading zeros)
=  2   7   5  (convert each group of three into octal)
= 275 (base eight).```
To convert from binary to hexadecimal, use the "group by fours" technique. For example,
```10111101 (base two)
= 1011 1101 (break into groups of four)
=   B   D   (convert each group of four into hexadecimal)
= BD (base sixteen).
```
Thus, 10111101 (base two) equals 275 (base eight) equals BD (base sixteen).

WORKSHEET #25:

• (W25.1) There's a neat base converter located at:
http://www.triumphpc.com/base/
Check it out!
• (W25.2) We'll be continuing the online tutorial in a few days. The first two in the series have been finished, and we're moving on to the third, entitled "Here's Wilbur!"
Please read the FOREWORD, INTRODUCTION, and REQUIREMENTS in this third tutorial, located at:
http://www.cwru.edu/help/wilbur/ (link is no longer valid)

ASSIGNMENT #25:

• (A25.1) Be sure that you can do the following: if I give you a number like 326 (base 7), you should be able to convert it to base ten. (By hand! Not using the online base converter.)
• (A25.2) Be able to convert any binary number to both octal and hexadecimal.
On to the next lesson!
Back to the COURSE SYLLABUS