CS 100 (Learn)CS 100 (Web)Module 01


Converting to Decimal

(direct YouTube link)

NOTE: If your internet access is restricted and you do not have access to YouTube, we have provided alternate video links.

TRANSCRIPT

In this video we are going to learn how to interpret and convert numbers from different bases into decimal (base ten).

All of our lives, we have been using base ten, which has ten digits (zero through nine) but now we know about different bases.

We are going to need a notation to distinguish between numbers from different bases.

If I show you the number one one [11] you would normally presume that it is the number eleven in base ten. However, if it is in binary (or base two) it would actually be the equivalent of our number "three". If it is in hexadecimal (or base sixteen) it would be the equivalent of our "seventeen".

Moving forward, we will use subscripts to indicate the base of the number.

1110 is "eleven" 112 is "three" 1116 is "seventeen"

If a number does not have a subscript, or any other mention of its base, then you may assume that it is in base ten.

Before we learn how to do those conversions, we will first re-learn how we interpret numbers in base ten.

A number is made up of digits in different columns. For the number five nine seven eight [5978], the digit five is in column three, the digit nine is in column two, the digit seven is in column one, and the digit eight is in column zero.

number:             5      9      7      8   (5978)
------------------------------------------
column #:           3      2      1      0
10^column:       10^3   10^2   10^1   10^0    
10^column:       1000    100     10      1

In base ten, we are used to saying that the eight is in the "ones column", the seven is in the "tens column", the nine is in the "hundreds column" and the five in the "thousands column".

The key observation is that each column corresponds to the the base raised to the exponent of the column number.

For example, column zero corresponds to "ten to the zero" which equals one [100 = 1]. Column three corresponds to "ten to the three" which equals one thousand [103 = 1000].

So the number five nine seven eight [5978] in base ten is really five times ten to the three plus nine times ten to the two plus seven times ten to the one, and eight times ten to the zero.

We intuitively know this, but it's useful to review exactly how it works.

The only thing that changes when we change the base system is the base of the exponents... that is all.

So using this method, let's look at how a number in base two would be interpreted.

11010‬2

Let's number our columns. Instead of the columns being "ones, tens, and hundreds", the columns will correspond to powers of two: "ones, twos, fours, eights, and sixteens".

So this number is: one times sixteen plus one times eight plus zero times four plus one times two plus zero times one, which equals twenty six (2610)

Let's do one more example:

100000112

Taking a short cut, we can ignore any columns with zeros. This number is one hundred and twenty-eight [128] plus two plus one, which equals one hundred and thirty-one in base ten [13110].

Let's look at an example in hexadecimal (or base 16, or simply "hex").

Before we do that, we might need a reminder for how the extra digits in hex work.

This table shows you at a glance how the first sixteen numbers look in decimal, binary and hex. This table will be provided on exams.

The first extra digit "A" is after nine, and has a value of ten. The last extra digit "F" has a value of fifteen.

| Decimal | Binary | Hex |  
|---------|--------|-----|
|       0 |   0000 |   0 |
|       1 |   0001 |   1 |
|       2 |   0010 |   2 |
|       3 |   0011 |   3 |
|       4 |   0100 |   4 |
|       5 |   0101 |   5 |
|       6 |   0110 |   6 |
|       7 |   0111 |   7 |
|       8 |   1000 |   8 |
|       9 |   1001 |   9 |
|      10 |   1010 |   A |
|      11 |   1011 |   B |
|      12 |   1100 |   C |
|      13 |   1101 |   D |
|      14 |   1110 |   E |
|      15 |   1111 |   F |

Let's look at a number in hex and covert it to decimal:

Three F B base sixteen [3FB16].

Just as we did with base two, we number our columns and then determine the power of sixteen for each column. Our columns will be the "ones", the "sixteens", and the "two hundred and fifty-sixes".

So the value of three F B base sixteen is three times "two hundred and fifty six" plus F (which is fifteen) times sixteen plus B (which is eleven) times one, which equals one thousand and nineteen in base ten [3FB16 = 3 * 256 + 15 * 16 + 11 * 1 = 101910].

That's all there is, really. To convert into decimal, you need to:

Now you can convert a number from any base in to decimal.