Positional Number Systems

55
Positional Number Systems Jim Williams HONP112 Week 1 Rev. 9/2011

description

Positional Number Systems. Jim Williams HONP112 Week 1 Rev. 9/2011. Why Math?. To understand computers, we will become familiar with a little math background. We will not get into anything very difficult We will, however, look at numbers a bit differently than we normally do. - PowerPoint PPT Presentation

Transcript of Positional Number Systems

Page 1: Positional  Number  Systems

Positional Number Systems

Jim WilliamsHONP112

Week 1Rev. 9/2011

Page 2: Positional  Number  Systems

To understand computers, we will become familiar with a little math background.

We will not get into anything very difficult We will, however, look at numbers a bit

differently than we normally do.

Why Math?

Page 3: Positional  Number  Systems

Numbering systems are necessary to represent quantities of things and to perform math.

It is important to understand that there can be more than one way to represent the same quantity.

Numbering Systems

Page 4: Positional  Number  Systems

In Roman numerals the symbol is XVII. Using tick marks the symbol is IIII IIII IIII II. Using a decimal number, the symbol is 17 Using a binary number the symbol is 10001

(more about that later!) Can you think of any others?

Example: the quantity “seventeen”

Page 5: Positional  Number  Systems

In our previous example, notice something important. For the Roman Numerals and Tick Marks, the position / column that the digits were in did not matter. The same digit represented the same quantity, regardless of the column.

We are not concerned with these systems for this course.

Non-positional systems

Page 6: Positional  Number  Systems

Notice however that in the decimal and binary systems, the column that the symbol was in did matter.

Positional numbering systems are only possible because of a placeholder value (the zero).

This allows the concept of a “place value” where the same digit can represent a different quantity, depending on the column.

These systems can be understood in terms of digits, positions, and bases.

Positional systems

Page 7: Positional  Number  Systems

A single digit symbol consists of a single instance of a certain number of different values.

These values always start with 0 and increment. Of course, we eventually run out of digit values

when representing numbers in a single digit (try counting to twenty-five using a single digit).

When we run out of “space” when using a single digit, we have to carry into the next position.

Digits

Page 8: Positional  Number  Systems

Let’s look at the positions in our own numbering system.1000s 100s 10s 1s3 0 8 7

The value of the digit depends on which column, or position, it is in.

You can see how the quantity 3,087 is really represented by adding the quantities represented by each symbol in the columns.

Positions (AKA Columns)

Page 9: Positional  Number  Systems

* Positions are numbered from RIGHT to LEFT, starting with ZERO (we will not deal with fractional numbers)

In our example: 3,087 the “7” is in position 0, the 8 is in position 1, and so on.

What numeric value does the digit in position 1 have?

More on Positions

Page 10: Positional  Number  Systems

In the number 3,087 , the true numeric value – commonly called the “place value” - of the digit in position 1 is 80, not 8.

Why? Because position 1 is the “10s” column, we multiply the digit value (8) by 10. 8 x 10 = 80.

Adding all the numeric values of each digit gives us our total of 3,087.

Place value of a digit

Page 11: Positional  Number  Systems

The Base (AKA “Radix”) of a numbering system determines two important things:◦ 1. The number of possible values that can be

represented by a single digit symbol.◦ 2. What the columns represent powers of.

Remember that this is critical to determining the place value of digits, relative to their columns.

So what about the Base?

Page 12: Positional  Number  Systems

Without knowing the base of a symbol, we have no way to know for certain the quantity that is represented by the symbol.

For example, consider the symbol “702”. What quantity does this symbol represent if

the columns are powers of 10? How about powers of 12?

Why the base is important

Page 13: Positional  Number  Systems

We use the decimal (Base-10) number system every day.

The prefix “dec” means “ten” (example: a decade is a period of 10 years)

You probably felt our last example was simple. Let’s examine it a bit further.

The Decimal Number System

Page 14: Positional  Number  Systems

Each digit can have one of only 10 possible values. {0,1,2,3,4,5,6,7,8,9}

Position numbers represent powers of 10 So, the numeric value of a digit in a position

can be calculated as follows n = d * (bp)

◦ d=digit value, b=base (10), and p=position number.

Base-10 digits and positions

Page 15: Positional  Number  Systems

Remember, a power is how many times a number is multiplied by itself.

For example, 10 raised to the 3rd power (written as 103), is 10x10x10, or 1000.

Exception: Any number raised to the zero power is always 1 (ex. 100 = 1, 20=1, etc.)

Powers

Page 16: Positional  Number  Systems

Let’s look at the positions in our own numbering system (Base-10) once again.1000s 100s 10s 1s3 0 8 7

This can also be understood in terms of powers of 10. 103 102 101 10o

3 0 8 7

Base-10 Powers and Positions

Page 17: Positional  Number  Systems

Using 3,087 as an example, we find the individual value of each digit, then add them together

n = 3 * (103) = 3,000 n = 0 * (102) = 0 n = 8 * (101) = 80 n = 7 * (100) = 7 3,000+0+80+7 = 3,087

Quantity represented by a Base-10 number

Page 18: Positional  Number  Systems

Now that we understand the way the base-10 system works, let’s try something a little different.

It is possible to use bases larger than 10, which might seem strange to us.

We will use the Hexadecimal (base-16) system as an example.

Notation: For bases other than 10, we sometimes write the base in subscript. For clarity we will do this in some examples.

The Hexadecimal Number System

Page 19: Positional  Number  Systems

Since the base is 16, this means that a single digit can have one of 16 possible values

These are {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} The digit A represents the quantity “10”,

the digit B represents the quantity “11”, and so on until we reach F, which represents the quantity “15”.

Hexadecimal (Base-16) Digits

Page 20: Positional  Number  Systems

7816 2D16 1F016 You must keep in mind that since the base

of the hexadecimal number system is 16, the actual quantity represented by these numbers is different than we first think (ie. the first number is NOT “seventy-eight.”)

Hexadecimal Number Examples

Page 21: Positional  Number  Systems

In the following slides, we will examine an example hexadecimal number.

We will also describe the numbering system rules in a similar way that we described the Base-10 rules.

Using these rules, we can convert a hexadecimal number to something we understand.

How do we understand Base-16 numbers?

Page 22: Positional  Number  Systems

For an example, let’s use 2E16. Since we are told it is hexadecimal, we

know that the numbering system has a base of 16.

Knowing this, we can evaluate the value of each digit and add them just like we did for decimal numbers.

Example Hexadecimal Number

Page 23: Positional  Number  Systems

Each digit can have one of only 16 possible values. (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)

Position numbers represent powers of 16 So, the numeric value of a digit in a position

can be calculated as follows n = d * (bp) d=digit value, b=base (16), and p=position

number.

Base-16 digits and positions

Page 24: Positional  Number  Systems

You already know what a power is. Here are some powers of 16. 160=1 161 = 16 162 = 16x16 = 256 Try some others yourself.

Remember your Powers of 16

Page 25: Positional  Number  Systems

Our Base-16 number example is 2E Let’s look at the digits in their positions. This time, we use powers of 16.

161 16o

2 E Which can also be seen as

16s 1s2 E

Base-16 Powers and Positions

Page 26: Positional  Number  Systems

Using 2E as an example, find the numeric value (or the quantity represented) of the digit in position 0

n = d * (bp) n = E * (160) [remember that E=14] n = 14

Quantity Represented a single digit in Base-16

Page 27: Positional  Number  Systems

Using 2E as an example, we find the individual value of each digit, then add them together

n = 2 * (161) = 32 n = E * (160) = 14 32+14 = 46 (our decimal equivalent)

Quantity Represented by a Base-16 number

Page 28: Positional  Number  Systems

As you can see we follow the same rules to determine the quantity represented by a symbol in any base.

Here are the steps illustrated. To do this we need to know both the

symbol, and the base. Let’s work through an example. Symbol =

675. Base = 8

Given a base and a symbol...

Page 29: Positional  Number  Systems

b2 b1 b0

Step 1: Prepare your column table

• Create a 2-row table for however many columns you have. The heading row will contain the column values.

• Notice that the column headings start with the power of zero in the rightmost column, and increment going left. The “b” is just a substitute for the base we will use.

Page 30: Positional  Number  Systems

82 81 80

Step 2: Enter your base in the column headings

• Notice that the column headings are in powers of 8 (the given radix).

Page 31: Positional  Number  Systems

82 81 80

6 7 5

Step 2: Draw in your symbol digits

• Our symbol 6758 is now placed in the correct columns.

Page 32: Positional  Number  Systems

82 81 80

6 7 5

Step 4: Determine the quantity represented by each single digit.

• 5 * 80 = 5 * 1 = 5• 7 * 81 = 7 * 8 = 56• 6 * 82 = 7 * 64 = 384

Page 33: Positional  Number  Systems

82 81 80

6 7 5

Step 5: Add them up.

• 5 * 80 = 5 * 1 = 5• 7 * 81 = 7 * 8 = 56• 6 * 82 = 6 * 64 = 384• 5 + 56 + 384 = 445• The symbol 675 in Base 8 represents the

quantity 445.

Page 34: Positional  Number  Systems

Another example: in class

• Using the five steps, work out the quantity represented by the symbol 3021 in base-4.

Page 35: Positional  Number  Systems

In our base-8 example, could we have had a digit symbol of 8? Of 9?

NO. Because in base 8, we can only have 8 digit symbols, starting with zero. These would be {0,1,2,3,4,5,6,7}.

If any digit represents a quantity greater than or equal to the base, it is not valid.

Keeping it legal

Page 36: Positional  Number  Systems

Symbol = 390 Base = 5 Symbol = 673 Base = 9 Symbol = 120 Base = 2 Symbol = 101 Base = 2 Symbol = 8AC Base = 16 Symbol = 8AC Base = 11 Symbol = 9004 Base = 10.

Are these legal or not?

Page 37: Positional  Number  Systems

Symbol = 390 Base = 5 ILLEGAL (9) Symbol = 673 Base = 9 Legal Symbol = 120 Base = 2 ILLEGAL (2) Symbol = 101 Base = 2 Legal Symbol = 8AC Base = 16 Legal Symbol = 8AC Base = 11 ILLEGAL (C) Symbol = 9004 Base = 10 Legal

Are these legal or not?

Page 38: Positional  Number  Systems

Computers use the Binary (Base-2) number system.

As you already know, the prefix “bi” means “two” (bi-cycle, bi-weekly, etc.)

The digital electronics used by the computer are based on the binary number system.

The Binary Number System

Page 39: Positional  Number  Systems

A binary digit is called a Bit (short for binary digit).

Bits can have a value of either 0 or 1 The 0 and 1 correspond with the electronic

states of “low/high” or “off/on”. These values also have a logical value of

“false/true”

Binary (Base-2) Digits

Page 40: Positional  Number  Systems

10012 0100102 1112 You must keep in mind that since the base

of the binary number system is 2, the actual quantity represented by these numbers is different than we first think (ie. the 3rd number is NOT one-hundred-eleven)

Binary Number Examples

Page 41: Positional  Number  Systems

In the following slides, we will examine an example binary number.

We will also describe the numbering system rules in a similar way that we described the Base-10 rules.

Using these rules, we can convert a binary number to something we understand.

How do we understand binary numbers?

Page 42: Positional  Number  Systems

For an example, let’s use 1101. Since we are told it is binary, we know that

the numbering system has a base of 2. Knowing this, we can evaluate the value of

each digit and add them just like we did for decimal numbers.

Example Binary Number

Page 43: Positional  Number  Systems

Each digit can have one of only 2 possible values. (0,1)

Position numbers represent powers of 2 So, the numeric value of a digit in a position

can be calculated as follows n = d * (bp) d=digit value, b=base (2), and p=position

number.

Base-2 digits and positions

Page 44: Positional  Number  Systems

You already know what a power is. Here are some powers of 2. 20=1 21 = 2 23 = 2x2x2 = 8 25 = 2x2x2x2x2 = 32 Try some others yourself.

Remember your Powers of 2

Page 45: Positional  Number  Systems

Our Binary number example is 1101 Let’s look at the digits in their positions. This time, we use powers of 2. 23 22 21 2o

1 1 0 1 Which can also be seen as 8s 4s 2s 1s1 1 0 1

Base-2 Powers and Positions

Page 46: Positional  Number  Systems

Using 1101 as an example, find the numeric value of the digit in position 3

n = d * (bp) n = 1 * (23) n = 8

Numeric value of a single digit in Base-2

Page 47: Positional  Number  Systems

Using 1101 as an example, we find the individual value of each digit, then add them together

n = 1 * (23) = 8 n = 1 * (22) = 4 n = 0 * (21) = 0 n = 1 * (20) = 1 8+4+0+1 = 13 (our decimal

equivalent)

Numeric value of a Base-2 number

Page 48: Positional  Number  Systems

We used the formula n = d * (bp) to find the numeric value of each single digit.

However, in binary, d will always be either 0 or 1.

Therefore, we can simplify our formula.

Notice Something

Page 49: Positional  Number  Systems

If a zero, ignore it (it is still 0). If a 1, it is equal to the position multiplier So, our original single digit numeric value

formula, n = d * (bp) , becomes simply: n = (bp) , where d=1

Numeric value of a single digit in Base-2, simplified.

Page 50: Positional  Number  Systems

Let’s use 11001000. Positions 0,1,2,4,and 5 contain zeroes. So

we ignore them. As for the rest… Position 7: n = (bp) = (27) = 128 Position 6: n = (bp) = (26) = 64 Position 3: n = (bp) = (23) = 8 128+64+8 = 200 (our decimal

equivalent)

Let’s try a bigger Base-2 Number

Page 51: Positional  Number  Systems

What is the numeric (decimal) value of the binary number 111010 ?

1. Place digits into the columns25 24 23 22 21 20

1 1 1 0 1 0 2. Add the numeric values of each “1” digit 25 + 24 + 23 + 21 , or 32 + 16 + 8 + 2 Answer = 58

Another Example

Page 52: Positional  Number  Systems

The general algorithm for adding any two whole numbers of any base, one digit at a time, is illustrated in the next slide.

You use the same algorithm whenever you add 2 Base-10 numbers every day. You probably just don’t think about it in much detail.

Adding Numbers of any Base

Page 53: Positional  Number  Systems

1. Start at the rightmost column with carry value set to zero.

2. Starting at the rightmost position, add the two quantities represented by the digits to the current carry value.

3. If the sum is greater than or equal to the base, subtract the base from the sum and set the carry to one. Place the remainder in the result digit.

4. If sum is less than the base, set the carry to zero. Place the sum in the result digit.

5. Move to the next column (to the left). Repeat from step 2 until you are out of columns to add.

6. If carry still equals one, create a new leftmost result column and place the carry in it.

Base-n Addition Algorithm

Page 54: Positional  Number  Systems

Try adding any 2 numbers of any (positive integer) base using the algorithm.

Example: Two Base-5 numbers (43, 14) The sum in Base-5 representation is 112. Why?? Bonus question: What actual quantity is

represented by the Base-5 number 112?

Addition: Try it

Page 55: Positional  Number  Systems

Base-2: 11 + 1 = 100 Base-2: 110 + 1 = 111 Base-8: 46 + 4 = 52 Base-16: 46 + 7 = 4D Base-6: 15 + 1 = 20 Base-10: 46 + 6 = 52 Base-12: 1B + 2 = 21 * Use the base-n addition algorithm to

verify these results! *

Some more addition Examples