62
CSCI N301: CSCI N301: Fundamental Computer Fundamental Computer Science Concepts Science Concepts Copyright Copyright ©2006 ©2006 Department of Computer & Information Science Department of Computer & Information Science The Switch, Part One The Switch, Part One

CSCI N301: Fundamental Computer Science Concepts Copyright ©2006 Department of Computer & Information Science The Switch, Part One

Embed Size (px)

Citation preview

Page 1: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

CSCI N301:CSCI N301: Fundamental Computer Fundamental Computer Science ConceptsScience Concepts

Copyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

The Switch, Part OneThe Switch, Part One

Page 2: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

GoalsGoals

By the end of this unit, you should By the end of this unit, you should understand …understand …

• Why computers use switches.Why computers use switches.• Why computers encode everything Why computers encode everything

using binary numbers.using binary numbers.• How to convert to and from Base-2.How to convert to and from Base-2.• How to convert to and from Base-8.How to convert to and from Base-8.• How to convert to and from Base-16.How to convert to and from Base-16.

Page 3: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Why do computers use Why do computers use switches?switches?

• Engineers selected a binary-state Engineers selected a binary-state (two state) switch as the (two state) switch as the fundamental computer fundamental computer component building block.component building block.

• Why? It was simple and reliable Why? It was simple and reliable and it supported built-in error and it supported built-in error checking.checking.

Page 4: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

The Switch and ArchitectureThe Switch and Architecture

• The innermost physical layer of a The innermost physical layer of a computer is a huge collection of computer is a huge collection of simple, two state switches.simple, two state switches.

• We can store any thing we want We can store any thing we want inside a computer, as long as we can inside a computer, as long as we can figure out how to translate it into a figure out how to translate it into a collection of switches …collection of switches …

Page 5: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Switches and MeaningSwitches and Meaning

• With one switch, how many messages can With one switch, how many messages can we convey? Two – I could let the open we convey? Two – I could let the open (“ON”) position represent the message (“ON”) position represent the message “Yes, we’ll have class today.”, while the “Yes, we’ll have class today.”, while the closed (“OFF”) position stands for “No, we closed (“OFF”) position stands for “No, we will not.”will not.”

• That’s not a lot of information, though, just That’s not a lot of information, though, just two things …two things …

Page 6: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Putting Them TogetherPutting Them Together

• What if I take two switches, put together?What if I take two switches, put together?• Now, I have four things I can say:Now, I have four things I can say:

– ON, ON: We’ll have class and a test.ON, ON: We’ll have class and a test.– ON, OFF: We’ll have class, but no test.ON, OFF: We’ll have class, but no test.– OFF, ON: We won’t have class, but we’ll have a OFF, ON: We won’t have class, but we’ll have a

test.test.– OFF, OFF: We won’t have class and we won’t OFF, OFF: We won’t have class and we won’t

have a test.have a test.

Page 7: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Adding Switches Doubles Adding Switches Doubles MessageMessage

• 1 switch = 2 message1 switch = 2 message• 2 switches = 4 messages2 switches = 4 messages• 3 switches = 8 messages3 switches = 8 messages• 4 switches = ? messages4 switches = ? messages• Do you see a pattern?Do you see a pattern?

Page 8: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Units of Computer Units of Computer MeasurementMeasurement

• The smallest unit of computer The smallest unit of computer measurement is a binary digit (or measurement is a binary digit (or more commonly, the “bit”). more commonly, the “bit”).

• The bit represents a single binary The bit represents a single binary digit, either a 1 or a 0. digit, either a 1 or a 0.

Page 9: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Larger Units of Larger Units of MeasurementMeasurement

• Bit = A single binary digitBit = A single binary digit• Nibble = 4 BitsNibble = 4 Bits• Byte = 2 Nibbles = 8 BitsByte = 2 Nibbles = 8 Bits• Word = 2 Bytes = 16 BitsWord = 2 Bytes = 16 Bits• Double Word = 2 Words = 32 BitsDouble Word = 2 Words = 32 Bits• Kilobyte = 1024 BytesKilobyte = 1024 Bytes• Megabyte = 1024 KilobytesMegabyte = 1024 Kilobytes• Gigabyte = 1025 MegabytesGigabyte = 1025 Megabytes

Page 10: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Starting with NumbersStarting with Numbers

• Each switch can either have sufficient voltage Each switch can either have sufficient voltage (“ON”) or have insufficient voltage (“OFF”).(“ON”) or have insufficient voltage (“OFF”).

• Another way of stating voltage: 1 or 0Another way of stating voltage: 1 or 0• This is a common approach in science – to use This is a common approach in science – to use

abstract, notational systems to describe abstract, notational systems to describe things.things.

“1”“1”

“0”“0”

Page 11: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Numbering SystemsNumbering Systems

• To figure the answer to this question, let’s To figure the answer to this question, let’s step back and look at numbering systems step back and look at numbering systems in general.in general.

• Originally, human being counted with tally Originally, human being counted with tally math systems, with a mark for each sheep math systems, with a mark for each sheep they were countingthey were counting– If you had 10 sheep, you made 10 marksIf you had 10 sheep, you made 10 marks

Page 12: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Numbering SystemsNumbering Systems

• Later, there were advancements in tally Later, there were advancements in tally math, using special symbols for special math, using special symbols for special numbers.numbers.– Instead of 10 marks for 10 sheep, let’s make a Instead of 10 marks for 10 sheep, let’s make a

special mark for 10 sheep …special mark for 10 sheep …

• But this notational system was But this notational system was cumbersome… you had to learn a lot of cumbersome… you had to learn a lot of symbols, and arithmetic was difficultsymbols, and arithmetic was difficult

==XX

Page 13: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Positional Numbering Positional Numbering SystemsSystems

• Wonderful advancement over tally Wonderful advancement over tally math.math.

• Let’s keep a few, core numbers (digits).Let’s keep a few, core numbers (digits).• We can use these digits to represent We can use these digits to represent

REALLY big numbers if we say that the REALLY big numbers if we say that the value of a number is now made up of 2 value of a number is now made up of 2 parts: parts: – A count valueA count value– A place valueA place value

Page 14: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Place ValuesPlace Values

• Consider the number 37…Consider the number 37…• The 7 stands for 7 (it’s count value) The 7 stands for 7 (it’s count value)

ones (it’s positional value). Together, ones (it’s positional value). Together, 7 times 1 is 77 times 1 is 7

3 73 7

Page 15: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Place ValuesPlace Values

• Consider the number 37…Consider the number 37…• The 3 stands for 3 (it’s count value) The 3 stands for 3 (it’s count value)

tens (it’s positional value). Together, tens (it’s positional value). Together, 3 times 10 is thirty3 times 10 is thirty

3 73 7

Page 16: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Place ValuesPlace Values

• Consider the number 37…Consider the number 37…• Total value: 7 (7 * 1, from the Total value: 7 (7 * 1, from the

ones position) and thirty (3 * 10, ones position) and thirty (3 * 10, from the 10 position) is 37!from the 10 position) is 37!

3 73 7

Page 17: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Place ValuesPlace Values

3 73 7“O

nes

”“Ten

s”

7 * 13 * 10

Page 18: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Base-10 (Decimal)Base-10 (Decimal)

• A base refers to the number of digits A base refers to the number of digits (counting numbers) available in a (counting numbers) available in a numbering scheme. numbering scheme.

• The highest single digit in base is one The highest single digit in base is one less than the base number.less than the base number.

• In Base-10, the digits are:In Base-10, the digits are:– 0, 1, 2, 3, 4, 5, 6, 7, 8, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9

Page 19: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Base-10 (Decimal)Base-10 (Decimal)

• What happens after 9?What happens after 9?• The counter in the right column resets The counter in the right column resets

itself to “0” and 1 is added to the itself to “0” and 1 is added to the value of the next left-most column:value of the next left-most column:

00 9 9 1 01 0

Page 20: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Base-10 (Decimal)Base-10 (Decimal)

• Interpreting a multiple digit number simply Interpreting a multiple digit number simply means to expand its notation, and write it out means to expand its notation, and write it out by each positional value:by each positional value:

7 4 27 4 2“Ones”2 * 1

“Tens”4 * 10

“Hundreds”

7 * 100

Page 21: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Base-10 (Decimal)Base-10 (Decimal)

• What about using some math to describe the What about using some math to describe the number:number:

7 4 27 4 210

02 * 1004 * 1017 * 102

101

102

Page 22: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Using Expanded NotationUsing Expanded Notation

• We can use our expanded notation to We can use our expanded notation to figure the value of a number:figure the value of a number:

7*107*1022 = 7*100 = 700 = 7*100 = 700

4*104*1011 = 4*10 = 40 = 4*10 = 40

2*102*1000 = 2*1 = 2 = 2*1 = 2

= 742= 7421010

Page 23: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

A Note on SuperscriptsA Note on Superscripts

• We’ve seen We’ve seen superscriptssuperscripts in in expressions before today. In expressions before today. In math, they are used to indicate math, they are used to indicate an an exponentexponent in an expression: in an expression:

xxyy

Page 24: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

A Note on SubscriptsA Note on Subscripts

• Let’s introduce one more Let’s introduce one more notation – the notation – the subscriptsubscript. It is . It is used to indicate the used to indicate the base of a base of a numbernumber (the number of digits (the number of digits available in a numbering available in a numbering system):system): xxyy

Page 25: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

A Note on SubscriptsA Note on Subscripts

• Remember our previous example?Remember our previous example?

• It had a subscript of “10”, meaning that It had a subscript of “10”, meaning that the number we use the Base-10 the number we use the Base-10 (Decimal) numbering system to decode (Decimal) numbering system to decode this number.this number.

7427421010

Page 26: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Thinking in Binary (Base-2)Thinking in Binary (Base-2)

• Instead of having 10 digits, the binary (Base-Instead of having 10 digits, the binary (Base-2) numbering systems has 2 base digits (0 2) numbering systems has 2 base digits (0 and 1).and 1).– Counting in Base-2: 0, 1, 10, 11, 100, 101, 110, Counting in Base-2: 0, 1, 10, 11, 100, 101, 110,

111, 1000, 1001, 1010 …111, 1000, 1001, 1010 …

• In binary, after the right-most placeholder In binary, after the right-most placeholder reaches one, it resets to 0 and advances the reaches one, it resets to 0 and advances the next left-most placeholder.next left-most placeholder.

• Our base number in binary is 2, therefore we Our base number in binary is 2, therefore we can use exponents of 2 for placeholder can use exponents of 2 for placeholder notationnotation

Page 27: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Binary PlaceholdersBinary Placeholders

1 0 1 11 0 1 1“T

wo

s”

“On

es”

“Fo

urs

“Eig

hts

• Let’s deconstruct 1011Let’s deconstruct 101122::

Page 28: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Binary PlaceholdersBinary Placeholders

1 0 1 11 0 1 120

• Now, let’s use exponents:Now, let’s use exponents:

212223

Page 29: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-2 to Base-Converting Base-2 to Base-1010

• Let’s convert Let’s convert 1011101122..

• STEP 1STEP 1: Find all : Find all switches that are switches that are turned “OFF”. turned “OFF”. Cross them out Cross them out and bring down and bring down the zero.the zero.

1 0 1 11 0 1 120212223

00

Page 30: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-2 to Base-Converting Base-2 to Base-1010

• STEP 2STEP 2: For each : For each placeholder placeholder turned “ON”, turned “ON”, calculate its calculate its exponential exponential expression.expression.

1 0 1 11 0 1 120212223

00 112288

Page 31: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-2 to Base-Converting Base-2 to Base-1010

• STEP 3STEP 3: Add the : Add the results of the results of the exponents. The exponents. The sum is the Base-sum is the Base-10 equivalent.10 equivalent.

1 0 1 11 0 1 120212223

00 112288++ ++ ++ ==11111010

Page 32: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting from Base-10 to Converting from Base-10 to Base-2Base-2

• Consider 23Consider 231010.. How can we How can we translate this to its Base-2 translate this to its Base-2 equivalent?equivalent?

• We’ll use We’ll use successive divisionsuccessive division. . Essentially, that means we’ll Essentially, that means we’ll divide by 2 over and over and divide by 2 over and over and keep track of our remainders.keep track of our remainders.

• Let’s try it …Let’s try it …

Page 33: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-22

STEP ONE: Draw STEP ONE: Draw a table with a table with three columns. three columns. Label the last Label the last two columns two columns quotient and quotient and remainder, remainder, respectively.respectively.

QQ RR

Page 34: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-22

STEP TWO: In the STEP TWO: In the first available left-first available left-most column, put most column, put the expression the expression 23/2. Calculate the 23/2. Calculate the division and put the division and put the quotient and quotient and remainder in their remainder in their respective columns.respective columns.

QQ RR

23/223/2 1111 11

Page 35: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-22

STEP THREE: Take STEP THREE: Take the quotient of the quotient of the previous the previous expression and expression and divide it by two. divide it by two. Repeat until have Repeat until have 0 for a quotient.0 for a quotient.

QQ RR

23/223/2 1111 11

11/211/2 55 11

5/25/2 22 11

2/22/2 11 00

1/21/2 00 11

Page 36: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-22

STEP FOUR: Read STEP FOUR: Read the REMAINDER the REMAINDER column from the column from the bottom to the top. bottom to the top. The 1s and 0s in The 1s and 0s in the remainder the remainder column represent column represent the binary the binary number.number.

QQ RR

23/223/2 1111 11

11/211/2 55 11

5/25/2 22 11

2/22/2 11 00

1/21/2 00 11

Page 37: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-22

23231010 = 10111 = 1011122

QQ RR

23/223/2 1111 11

11/211/2 55 11

5/25/2 22 11

2/22/2 11 00

1/21/2 00 11

Page 38: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Checking the ResultsChecking the Results

• So.. 23So.. 2310 10 = 10111 = 101112!2!

• Let’s check our answer by Let’s check our answer by reversing the processreversing the process

• 10111101112 2 = (1 * 2= (1 * 244) + (0 * 2) + (0 * 23 3 ) + ) + ( 1 * 2( 1 * 22 2 ) + (1 * 2) + (1 * 211) + (1 * 2) + (1 * 200) = ) =

• 16 + 0 + 4 + 2 + 1 = 2316 + 0 + 4 + 2 + 1 = 231010

Page 39: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Groups of SwitchesGroups of Switches

• We have already seen that a single We have already seen that a single switch can’t encode much information. switch can’t encode much information. However, if we group switches together, However, if we group switches together, we can expand our encoding ability. we can expand our encoding ability.

• Computers often encode many types of Computers often encode many types of data, graphics and large numbers for data, graphics and large numbers for example, not in Base-2, but in Base-8 or example, not in Base-2, but in Base-8 or Base-16.Base-16.

Page 40: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Introducing OctalIntroducing Octal

• Computer scientists are often looking Computer scientists are often looking for shortcuts to do things. One of the for shortcuts to do things. One of the ways in which we can represent ways in which we can represent Base-2 numbers is to use their octal Base-2 numbers is to use their octal (Base-8) equivalents.(Base-8) equivalents.

• This is especially helpful when we This is especially helpful when we have to do fairly complicated tasks have to do fairly complicated tasks using large numbers.using large numbers.

Page 41: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Introducing OctalIntroducing Octal

• The octal numbering system The octal numbering system includes eight base digits, 0-7.includes eight base digits, 0-7.

• After 7, the next placeholder to After 7, the next placeholder to the right begins with a 1:the right begins with a 1:0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 ... 13 ...

Page 42: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Octal DigitsOctal Digits

Base-2Base-2 Base-8Base-8 Base-10Base-10

000000 00 00

001001 11 11

010010 22 22

011011 33 33

100100 44 44

101101 55 55

110110 66 66

111111 77 77

Click to Return to the Last Slide ViewedClick to Return to the Last Slide Viewed

Page 43: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Octal PlaceholdersOctal Placeholders

““ Ones

On

es ””

““ Eig

hts

Eig

hts ””

““ Six

ty-

Six

ty-

Fou

rs”

Fou

rs”

64*264*2 8*48*4 1*11*1

8822*2*2 8811*4*4 8800*1*1

22 44 11Number:Number:

Placeholder Placeholder Name:Name:

Value:Value:

Exponential Exponential Expression:Expression:

Page 44: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-2 to Base-8Converting Base-2 to Base-8

STEP ONE: Take the binary number and from right to left, group all placeholders in triplets. Add leading zeros, if necessary:

100011001010012

010 001101100001Click to See Octal Digits TableClick to See Octal Digits Table

Page 45: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-2 to Base-8Converting Base-2 to Base-8

STEP TWO: Convert each triplet to its single-digit octal equivalent. (HINT: For each triplet, the octal conversion is the same as converting to a decimal number):

100011001010012

010 001101100001

2 1 154

214518

=

Page 46: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-8 to Base-2Converting Base-8 to Base-2

Take each octal digit and convert each digit to a binary triplet. Insert leading zeros, if needed:

435208

100 0000101010114 3 025

1000111010100002

=

Click to See Octal Digits TableClick to See Octal Digits Table

Page 47: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-8 to Base-Converting Base-8 to Base-1010

Multiply each octal digit by the exponential expression that represents its placeholder and then add the values:

23748 =

N10

2*82*833 = 2*512 = 1024 = 2*512 = 1024 8

3*83*822 = 3*64 = 192 = 3*64 = 192 8

7*87*811 = 7*8 = 56 = 7*8 = 56 8 4*84*800 = 4*1 = 4 = 4*1 = 4 8

= 1276= 12761010

Page 48: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-88

To convert Base-10 to Base-8, To convert Base-10 to Base-8, we’ll use successive division …we’ll use successive division …

Our new problem:Our new problem:

483248321010 = ? = ?88

Page 49: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-88

STEP ONE: Draw STEP ONE: Draw a table with a table with three columns. three columns. Label the last Label the last two columns two columns quotient and quotient and remainder, remainder, respectively.respectively.

QQ RR

Page 50: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-88

STEP TWO: In the STEP TWO: In the first available left-first available left-most column, put most column, put the expression the expression 4832/8. Calculate 4832/8. Calculate the division and put the division and put the quotient and the quotient and remainder in their remainder in their respective columns.respective columns.

QQ RR

4832/84832/8 604604 00

Page 51: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-88

STEP THREE: Take STEP THREE: Take the quotient of the quotient of the previous the previous expression and expression and divide it by divide it by eight. Repeat eight. Repeat until you’ve have until you’ve have 0 for a quotient.0 for a quotient.

QQ RR

4832/84832/8 604604 00

604/8604/8 7575 44

75/875/8 99 33

9/89/8 11 11

1/81/8 00 11

Page 52: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-88

STEP FOUR: Read STEP FOUR: Read the REMAINDER the REMAINDER column from the column from the bottom to the bottom to the top. The numbers top. The numbers in the remainder in the remainder column represent column represent the octal number.the octal number.

QQ RR

4832/84832/8 604604 00

604/8604/8 7575 44

75/875/8 99 33

9/89/8 11 11

1/81/8 00 11

Page 53: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-88

483248321010 = 11340 = 1134088

QQ RR

4832/84832/8 604604 00

604/8604/8 7575 44

75/875/8 99 33

9/89/8 11 11

1/81/8 00 11

Page 54: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Base-16Base-16

• What’s tricky about Base-16?What’s tricky about Base-16?• This time, we are converting to a This time, we are converting to a

base that has more base digits base that has more base digits than Base-10 (Base-2 and Base-8 than Base-10 (Base-2 and Base-8 have fewer digits than Base-10)have fewer digits than Base-10)

• So what?So what?

Page 55: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Hexadecimal NumberingHexadecimal Numbering

• There are new symbols for the Base-16 There are new symbols for the Base-16 equivalents of the Base-10 numbers 10, equivalents of the Base-10 numbers 10, 11, 12, 14 and 15. Examine:11, 12, 14 and 15. Examine:

DECDEC 00 11 22 33 44 55 66 77

HEXHEX 00 11 22 33 44 55 66 77

DECDEC 88 99 1010 1111 1212 1313 1414 1515

HEXHEX 88 99 AA BB CC DD EE FF

Page 56: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-1616

To convert Base-10 to Base-16, To convert Base-10 to Base-16, we’ll again use successive we’ll again use successive

division …division …

Our new problem:Our new problem:

2142141010 = ? = ?1616

Page 57: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-1616

STEP ONE: Draw STEP ONE: Draw a table with a table with three columns. three columns. Label the last Label the last two columns two columns quotient and quotient and remainder, remainder, respectively.respectively.

QQ RR

Page 58: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-1616

STEP TWO: In the STEP TWO: In the first column, write first column, write the expression the expression 214/16. Calculate 214/16. Calculate the expression, the expression, taking care not to taking care not to divide past the divide past the decimal point. decimal point. Write the quotient Write the quotient and remainder in and remainder in their respective their respective columns.columns.

QQ RR

214/16214/16 1313 66

Page 59: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-1616

STEP THREE: Keep STEP THREE: Keep bringing down bringing down the quotient of the quotient of the previous the previous expression and expression and dividing it by 16 dividing it by 16 until you have a until you have a quotient of zero.quotient of zero.

QQ RR

214/16214/16 1313 66

13/1613/16 00 1313

Page 60: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-1616

STEP FOUR: STEP FOUR: Convert all Convert all remainders to remainders to their hex their hex equivalents.equivalents.

QQ RR

214/16214/16 1313 6 = 66 = 6

13/1613/16 0013 = 13 =

DD

Page 61: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Converting Base-10 to Base-Converting Base-10 to Base-1616

STEP FIVE: Read STEP FIVE: Read the numbers in the numbers in the REMAINDER the REMAINDER column from the column from the bottom up to get bottom up to get your hex your hex equivalent.equivalent.

QQ RR

214/16214/16 1313 6 = 66 = 6

13/1613/16 0013 = 13 =

DD

2142141010 = D6 = D61616

Page 62: CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One

N301: Fundamental Computer Science ConceptsN301: Fundamental Computer Science ConceptsCopyright Copyright ©2006 ©2006 Department of Computer & Information ScienceDepartment of Computer & Information Science

Questions?Questions?