Computer Science Introduction to the Number Base Unit Adapted from Slides by John Owen Computer Science Instructor, Rockport-Fulton High School, Rockport,

Slides:



Advertisements
Similar presentations
John Owen, Rockport Fulton HS
Advertisements

Data Representation COE 202 Digital Logic Design Dr. Aiman El-Maleh
HEXADECIMAL NUMBERS Code
Chapter 2: Data Representation
CHAPTER 2 Number Systems, Operations, and Codes
Floating Point Numbers
Digital Fundamentals Floyd Chapter 2 Tenth Edition
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Data Representation COE 205
Connecting with Computer Science, 2e
Assembly Language and Computer Architecture Using C++ and Java
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
Chapter 02 Binary Values and Number Systems Nell Dale & John Lewis.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
John Owen, Rockport Fulton HS1 Computer Science LESSON 2 ON Number Bases.
The Binary Number System
2.1 2 Number Systems Foundations of Computer Science  Cengage Learning.
Binary Arithmetic Math For Computers.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
LESSON ON Number Base Subtraction and Simple Equations
Real Numbers and the Decimal Number System
Data Representation Number Systems.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Simple Data Type Representation and conversion of numbers
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
Numbering systems.
Copyright © Cengage Learning. All rights reserved. CHAPTER 2 THE LOGIC OF COMPOUND STATEMENTS THE LOGIC OF COMPOUND STATEMENTS.
Number Systems Binary and Hexadecimal. Base 2 a.k.a. Binary  Binary works off of base of 2 instead of a base 10 like what we are taught in school 
Numeral Systems Subjects: Numeral System Positional systems Decimal
Numbering Systems CS208.
Numeration Systems Introduction to Binary, Octal, and Hexadecimal.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
1 IT 231, CMPE 331 Digital Logic Design Week 2 Number systems and arithmetic.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
Introduction to Number System
Data Representation, Number Systems and Base Conversions
How a Computer Processes Information. Java – Numbering Systems OBJECTIVE - Introduction to Numbering Systems and their relation to Computer Problems Review.
AEEE2031 Data Representation and Numbering Systems.
1 Computer Science LESSON 1 on Number Bases. 2 Objective In this lesson you’ll learn about different Number Bases, specifically about those used by the.
Computer Science Introduction to the Number Base Unit developed by John Owen Computer Science Instructor, Rockport-Fulton High School, Rockport, Texas.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Introduction To Number Systems Binary System M. AL-Towaileb1.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Introduction to Digital Electronics Lecture 2: Number Systems.
1 Discrete Math LESSON ON Number Base Addition. 2 Objective In this lesson you’ll learn how to do simple addition in Base 2, 8, and 16. It is essentially.
Computer Science LESSON 2 ON Number Bases.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Digital logic COMP214  Lecture 2 Dr. Sarah M.Eljack Chapter 1 1.
Binary Values. Numbers Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative Numbers.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
Digital Systems and Number Systems
Digital Electronics INTRODUCTION ANALOG VS DIGITAL NUMBER SYSTEMS.
COMPUTING FUNDAMENTALS
Computer Science LESSON 1 on Number Bases.
ITE102 – Computer Programming (C++)
Number Systems Lab session 1 Xuan Guo.
Number System conversions
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
AP Computer Science LESSON 1 on Number Bases.
John Owen, Rockport Fulton HS
Presentation transcript:

Computer Science Introduction to the Number Base Unit Adapted from Slides by John Owen Computer Science Instructor, Rockport-Fulton High School, Rockport, Texas

John Owen, Rockport Fulton HS2 Objective This unit of study is designed to introduce the beginner computer science students to the concept of the computer number bases (2, 8, and 16) and their computation.

John Owen, Rockport Fulton HS3 Part1 Different Number Bases, specifically about those used by the computer includes: Base Two – binary Base Eight – octal Base Sixteen – hexadecimal

John Owen, Rockport Fulton HS4 Base Ten “because it has ten counting digits, 0,1,2,3,4,5,6,7,8, and 9” To count in base ten, you go from 0 to 9, then do combinations of two digits starting with 10 all the way to 99

John Owen, Rockport Fulton HS5 Base Two To count in base two, which only has 0 and 1 as counting digits, you count 0,1, then switch to two digit combinations, 10,11, then to three digit combos, 100, 101,110,111, then four digit, 1000, _____,_______, …, 1111

John Owen, Rockport Fulton HS6 Base Three To count in base three, which has 0, 1, and 2 as counting digits, you count 0,1,2, then switch to two digit combinations, 10,11, 12, 20, 21, 22, then to three digit combos, 100, 101,102, 110,111, 112, etc…

John Owen, Rockport Fulton HS7 Base Eight base eight (often called octal)… The base eight counting sequence 0,1,2,3,4,5,6,7,10,11,12,13,…77 100,101,102,103,104,105,106, ,111, etc.

John Owen, Rockport Fulton HS8 Base Sixteen Base Sixteen, also known as hexadecimal, was especially created by computer scientists to help simplify low-level programming, like machine language and assembly language.

John Owen, Rockport Fulton HS9 Base Sixteen To get sixteen counting digits, you use 0- 9, but still need six more…so it was decided to use A,B,C,D,E, and F. 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Then the two-digit combos: 10,11,12,…19,1A,1B,1C,1D,1E,1F,20,21,22,…2D,2E,2F,30,31,…FF

John Owen, Rockport Fulton HS10 Base conversion To convert from base ten to another base, such as base two, eight, or sixteen, is an important skill for computer scientists and programmers.

John Owen, Rockport Fulton HS11 Base Ten to Base Two Let’s take the value 27 and convert it into base 2. Here’s the process: Divide 27 by 2 The answer is 13, remainder 1 Divide 13 by 2 Answer is 6, remainder 1

John Owen, Rockport Fulton HS12 Base Ten to Base Two Continue until the answer is 1. 6 divided by 2 = 3, remainder 0 3 divided by 2 = 1, remainder 1 Now take the last answer, 1, and all of the remainders in reverse order, and put them together… base 10 = base two

John Owen, Rockport Fulton HS13 Base Ten to Base Two Here’s an easy way to do it on paper 27 divided by 2 = 13, R 1

John Owen, Rockport Fulton HS14 Base Ten to Base Two 13 / 2 = 6, R 1

John Owen, Rockport Fulton HS15 Base Ten to Base Two 6 / 2 = 3, R 0

John Owen, Rockport Fulton HS16 Base Ten to Base Two 3 / 2 = 1, R 1

John Owen, Rockport Fulton HS17 Base Ten to Base Two Stop, and write the answer

John Owen, Rockport Fulton HS18 Base Ten to Base Two

John Owen, Rockport Fulton HS19 Exercises Now try a few yourself (see last slide for answers): = _________ = _________ = _________ = _________ = _________ 2

John Owen, Rockport Fulton HS20 Base Ten to Base Eight Let’s again take the value 27 and convert it into base 8. Same process: Divide 27 by 8 The answer is 3, remainder 3 Stop! You can’t divide anymore because the answer is less than 8

John Owen, Rockport Fulton HS21 Base Ten to Base Eight The last answer was 3, and the only remainder was 3, so the base eight value is 33, base 8.

John Owen, Rockport Fulton HS22 Base Ten to Base Eight Use the same method on paper 27 divided by 8 = 3, R 3 27, base 10 = 33, base 8

John Owen, Rockport Fulton HS23 Exercises Now try the same values for base eight = _________ = _________ = _________ = _________ = _________ 8

John Owen, Rockport Fulton HS24 Base Ten to Base Sixteen Finally we’ll convert 27 into base 16. Divide 27 by 16 The answer is 1, remainder 11 Stop! You can’t divide anymore because the answer is less than 16

John Owen, Rockport Fulton HS25 Base Ten to Base Sixteen The last answer was 1, and the only remainder was 11, which in base 16 is the letter B, so the base sixteen value is 1B, base 16.

John Owen, Rockport Fulton HS26 Base Ten to Base Sixteen Again, the same method on paper 27 divided by 16 = 1, R 11 or B 27, base 10 = 1B, base 16

John Owen, Rockport Fulton HS27 Exercises And now try base sixteen! = _________ = _________ = _________ = _________ = _________ 16

John Owen, Rockport Fulton HS28 Here are the answers to the exercises, in jumbled order 10 1F F

John Owen, Rockport Fulton HS29 Part 2: Other conversions Now you will learn other conversions among these four number systems, specifically: Binary to Decimal Octal to Decimal Hexadecimal to Decimal

John Owen, Rockport Fulton HS30 Other conversions As well as Binary to Octal Octal to Binary Binary to Hexadecimal Hexadecimal to Binary Octal to Hexadecimal Hexadecimal to Octal

John Owen, Rockport Fulton HS31 Binary to Decimal Each binary digit in a binary number has a place value. In the number 111, base 2, the digit farthest to the right is in the “ones” place, like the base ten system, and is worth 1. Technically this is the 2 0 place.

John Owen, Rockport Fulton HS32 Binary to Decimal The 2 nd digit from the right, 111, is in the “twos” place, which could be called the “base” place, and is worth 2. Technically this is the 2 1 place. In base ten, this would be the “tens” place and would be worth 10.

John Owen, Rockport Fulton HS33 Binary to Decimal The 3 rd digit from the right, 111, is in the “fours” place, or the “base squared” place, and is worth 4. Technically this is the 2 2 place. In base ten, this would be the “hundreds” place and would be worth 100.

John Owen, Rockport Fulton HS34 Binary to Decimal The total value of this binary number, 111, is 4+2+1, or seven. In base ten, 111 would be worth , or one-hundred eleven.

John Owen, Rockport Fulton HS35 Binary to Decimal Can you figure the decimal values for these binary values?

John Owen, Rockport Fulton HS36 Binary to Decimal answers: 11 is 3 in base ten 101 is is is is 27

John Owen, Rockport Fulton HS37 Octal to Decimal Octal digits have place values based on the value 8. In the number 111, base 8, the digit farthest to the right is in the “ones” place and is worth 1. Technically this is the 8 0 place.

John Owen, Rockport Fulton HS38 Octal to Decimal The 2 nd digit from the right, 111, is in the “eights” place, the “base” place, and is worth 8. Technically this is the 8 1 place.

John Owen, Rockport Fulton HS39 Octal to Decimal The 3 rd digit from the right, 111, is in the “sixty-fours” place, the “base squared” place, and is worth 64. Technically this is the 8 2 place.

John Owen, Rockport Fulton HS40 Octal to Decimal The total value of this octal number, 111, is , or seventy-three.

John Owen, Rockport Fulton HS41 Octal to Decimal Can you figure the value for these octal values?

John Owen, Rockport Fulton HS42 Octal to Decimal Here are the answers: 21 is 17 in base is is is is 1093

John Owen, Rockport Fulton HS43 Hexadecimal to Decimal Hexadecimal digits have place values base on the value 16. In the number 111, base 16, the digit farthest to the right is in the “ones” place and is worth 1. Technically this is the 16 0 place.

John Owen, Rockport Fulton HS44 Hexadecimal to Decimal The 2 nd digit from the right, 111, is in the “sixteens” place, the “base” place, and is worth 16. Technically this is the 16 1 place.

John Owen, Rockport Fulton HS45 Hexadecimal to Decimal The 3 rd digit from the right, 111, is in the “two hundred fifty-six” place, the “base squared” place, and is worth 256. Technically this is the 16 2 place.

John Owen, Rockport Fulton HS46 Hexadecimal to Decimal The total value of this hexadecimal number, 111, is , or two hundred seventy-three.

John Owen, Rockport Fulton HS47 Hexadecimal to Decimal Can you figure the value for these hexadecimal values? 2A 15F A7C 11BE A10D

John Owen, Rockport Fulton HS48 Hexadecimal to Decimal Here are the answers: 2A is 42 in base 10 15F is 351 A7C is BE is 4542 A10D is 41229

John Owen, Rockport Fulton HS49 Binary to Octal The conversion between binary and octal is quite simple. Since 2 to the power of 3 equals 8, it takes 3 base 2 digits to combine to make a base 8 digit.

John Owen, Rockport Fulton HS50 Binary to Octal 000 base 2 equals 0 base = = = = = = = 7 8

John Owen, Rockport Fulton HS51 Binary to Octal What if you have more than three binary digits, like ? Just separate the digits into groups of three from the right, then convert each group into the corresponding base 8 digit base 2 = 63 base 8

John Owen, Rockport Fulton HS52 Binary to Octal Try these: Hint: when the leftmost group has fewer than three digits, fill with zeroes from the left: = =

John Owen, Rockport Fulton HS53 Binary to Octal The answers are: = = = = = 635 8

John Owen, Rockport Fulton HS54 Binary to Hexadecimal The conversion between binary and hexadecimal is equally simple. Since 2 to the power of 4 equals 16, it takes 4 base 2 digits to combine to make a base 16 digit.

John Owen, Rockport Fulton HS55 Binary to Hexadecimal 0000 base 2 equals 0 base = = = = = = = 7 16

John Owen, Rockport Fulton HS56 Binary to Hexadecimal = = = A = B = C = D = E = F 16

John Owen, Rockport Fulton HS57 Binary to Hexadecimal If you have more than four binary digits, like , again separate the digits into groups of four from the right, then convert each group into the corresponding base 16 digit base 2 = D7 base 16

John Owen, Rockport Fulton HS58 Binary to Hexadecimal Try these: Hint: when the leftmost group has fewer than four digits, fill with zeroes on the left: = =

John Owen, Rockport Fulton HS59 Binary to Hexadecimal The answers are: = DC = B = = 1B = 1A5D 16

John Owen, Rockport Fulton HS60 Octal to Binary Converting from Octal to Binary is just the inverse of Binary to Octal. For each octal digit, translate it into the equivalent three-digit binary group. For example, 45 base 8 equals base 2

John Owen, Rockport Fulton HS61 Hexadecimal to Binary Converting from Hexadecimal to Binary is the inverse of Binary to Hexadecimal. For each “hex” digit, translate it into the equivalent four-digit binary group. For example, 45 base 16 equals base 2

John Owen, Rockport Fulton HS62 Octal and Hexadecimal to Binary Exercises Convert each of these to binary: A2D FF 16

John Owen, Rockport Fulton HS63 Octal and Hexadecimal to Binary Exercises The answers are: 63 8 = = (drop leading 0s) 75 8 = A2D 16 = = FF 16 =

John Owen, Rockport Fulton HS64 Hexadecimal to Octal Converting from Hexadecimal to Octal is a two-part process. First convert from “hex” to binary, then regroup the bits from groups of four into groups of three. Then convert to an octal number.

John Owen, Rockport Fulton HS65 Hexadecimal to Octal For example: 4A3 16 = =

John Owen, Rockport Fulton HS66 Octal to Hexadecimal Converting from Octal to Hexadecimal is a similar two-part process. First convert from octal to binary, then regroup the bits from groups of three into groups of four. Then convert to an hex number.

John Owen, Rockport Fulton HS67 Hexadecimal to Octal For example: = = = F9 8

John Owen, Rockport Fulton HS68 Octal/Hexadecimal Practice Convert each of these: 63 8 = ________ = ________ = ________ 16 A2D 16 = ________ = ________ 16 3FF 16 = ________ 8

John Owen, Rockport Fulton HS69 Octal/Hexadecimal Practice The answers are 63 8 = = = 3D 16 A2D 16 = = FF 16 =

John Owen, Rockport Fulton HS70 Part3: Counting, Place Value An introduction to the basic idea of counting in different bases and the place value system, associating it with the familiar base 10 system.

John Owen, Rockport Fulton HS71 Review Base Ten Addition, #1 In Base 10 addition, you learned a very simple process. Look at this problem: First add the ones column, then the tens.

John Owen, Rockport Fulton HS72 Review Base Ten Addition, # The answer is 49…simple, right?

John Owen, Rockport Fulton HS73 Review Base Ten Addition, #2 Now look at this problem: When you add the ones column values, the result of 10 EQUALS the base value of 10, so you have to CARRY a 1.

John Owen, Rockport Fulton HS74 Review Base Ten Addition, # When a carry is made, you essentially divide by 10 (the base) to determine what value to carry, and mod by 10 to determine what value to leave behind.

John Owen, Rockport Fulton HS75 Review Base Ten Addition,# plus 7 is divided by 10 is 1 (carry) 10 mod 10 is 0 (leave)

John Owen, Rockport Fulton HS76 Review Base Ten Addition, # Answer is 50

John Owen, Rockport Fulton HS77 Review Base Ten Addition, #3 Here’s a third example: When you add the ones column values, the result of 13 EXCEEDS the base value of 10, so CARRY a 1.

John Owen, Rockport Fulton HS78 Review Base Ten Addition, # plus 7 is divided by 10 is 1 (carry) 13 mod 10 is 3 (leave)

John Owen, Rockport Fulton HS79 Review Base Ten Addition, # Answer is 53

John Owen, Rockport Fulton HS80 Review Base Ten Addition, #4 And finally, a fourth example: The ones column result of 11 EXCEEDS the base value of 10, and you CARRY a 1.

John Owen, Rockport Fulton HS81 Review Base Ten Addition,# plus 5 is divided by 10 is 1 (carry) 11 mod 10 is 1 (leave)

John Owen, Rockport Fulton HS82 Review Base Ten Addition, # is 6 plus 5, which equals divided by 10 is 1 (carry) 11 mod 10 is 1 (leave)

John Owen, Rockport Fulton HS83 Review Base Ten Addition, # Answer is 111, base 10

John Owen, Rockport Fulton HS84 Base Eight Addition, #1 Now here is an example in base eight: When you add the ones column values, the answer is 6, and the second column answer is 4.

John Owen, Rockport Fulton HS85 Base Eight Addition. # Answer is 48, base eight You say, “four eight base eight”, not “forty-eight” The phrase “forty-eight” is meant for base ten only.

John Owen, Rockport Fulton HS86 Base Eight Addition, #2 Now look at this problem: When you add the ones column values, the result of 8 EQUALS the base value of 8, and you have to CARRY a one.

John Owen, Rockport Fulton HS87 Base Eight Addition, # Again you divide by 8 (the base) to determine what value to carry, and mod by 8 to determine what value to leave behind.

John Owen, Rockport Fulton HS88 Base Eight Addition, # plus 4 is 8 8 divided by 8 is 1 (carry) 8 mod 8 is 0 (leave)

John Owen, Rockport Fulton HS89 Base Eight Addition, # Answer is “five zero, base eight”! Looks strange, but it is correct!

John Owen, Rockport Fulton HS90 Base Eight Addition, #3 Here’s a third example: When you add the ones column values, the result of 13 EXCEEDS the base value of 8, and you have to CARRY a one.

John Owen, Rockport Fulton HS91 Base Eight Addition, # plus 7 is divided by 8 is 1 (carry) 13 mod 8 is 5 (leave)

John Owen, Rockport Fulton HS92 Base Eight Addition, # Answer is 55, base eight.

John Owen, Rockport Fulton HS93 Base Eight Addition, #4 And a fourth example: The ones column result of 11 EXCEEDS the base value of 8, …CARRY a one.

John Owen, Rockport Fulton HS94 Base Eight Addition, # plus 5 is divided by 8 is 1 (carry) 11 mod 8 is 3 (leave)

John Owen, Rockport Fulton HS95 Base Eight Addition, # is 6 plus 5 is divided by 8 is 1 (carry) 11 mod 8 is 3 (leave)

John Owen, Rockport Fulton HS96 Base Eight Addition, # Answer is 133, base 8

John Owen, Rockport Fulton HS97 Base Two Addition, #1 Base Two Addition is quite interesting, but also fairly simple. Since the only counting digits in base two are the values 0 and 1, there are only a few situations you have to learn.

John Owen, Rockport Fulton HS98 Base Two Addition, #1 We’ll start simple: 1 +1 =10 (“one zero, base two”) This looks strange, but the same process applies.

John Owen, Rockport Fulton HS99 Base Two Addition, # = 10 Since is 2, this EQUALS the base value of 2, which means you carry the “div” answer and leave the “mod” answer

John Owen, Rockport Fulton HS100 Base Two Addition, # = 10 2 / 2 = 1 (carry) 2 % 2 = 0 (leave) That’s it!

John Owen, Rockport Fulton HS101 Base Two Addition, #2 Here’s another: = 101 Can you figure it out?

John Owen, Rockport Fulton HS102 Base Two Addition, # = 101 In the ones column, is 1. In the second column, 1+1 is 2, or 10 in base 2

John Owen, Rockport Fulton HS103 Base Two Addition, #3 And another: = Can you figure it out?

John Owen, Rockport Fulton HS104 Base Two Addition, #3 Step by step… = 0

John Owen, Rockport Fulton HS105 Base Two Addition, #3 Step by step… = 00

John Owen, Rockport Fulton HS106 Base Two Addition, #3 Step by step… = 000

John Owen, Rockport Fulton HS107 Base Two Addition, #3 Step by step… = 0000

John Owen, Rockport Fulton HS108 Base Two Addition, #3 Step by step… = Since is 3, carry 1 and leave 1

John Owen, Rockport Fulton HS109 Base Two Addition, #3 Step by step… = All done!

John Owen, Rockport Fulton HS110 Base Sixteen, Example #1 In base sixteen, remember the digits are 0-9, then A-F, representing the values 0-15 Here’s an example:

John Owen, Rockport Fulton HS111 Base Sixteen, Example # = 3B, base is 11, which is B in base sixteen 2+1 is 3, so the answer is 3B

John Owen, Rockport Fulton HS112 Base Sixteen, Example #2 1 A9 +47 = F0, base is 16, equal to the base, so carry 1 and leave A(10) + 4 is 15, which is F

John Owen, Rockport Fulton HS113 Base Sixteen, Example #3 11 D6 +7C = 152, base 16 6+C(12) = 18, carry 1, leave 2 1+D(13)+7 = 21, carry 1, leave 5

John Owen, Rockport Fulton HS114 Base Sixteen, Example #4 11 EF +2D = 11C, base 16 F(15) + D(13) = 28, carry 1, leave C(12) 1 + E(14) + 2 = 17, carry 1, leave 1

John Owen, Rockport Fulton HS115 Exercises Now try these exercises = = 3. F 16 + F 16 = = B 16 = 6. C 16 + D 16 =

John Owen, Rockport Fulton HS116 Exercises = 8. F = = = = = =

John Owen, Rockport Fulton HS117 Exercises 14. ACE 16 + BAD 16 = = F =

John Owen, Rockport Fulton HS118 ANSWERS (JUMBLED) E BA9 8C B

John Owen, Rockport Fulton HS119 Part 4 In this section you’ll learn how to do subtraction and how to solve simple equations involving Base 2, 8, and 16. Again, it is essentially the same concept as Base 10, just in a different base!

John Owen, Rockport Fulton HS120 Review Base Ten Subtraction In Base 10 subtraction, you use a very simple process. Look at this problem: = 11

John Owen, Rockport Fulton HS121 Review Base Ten Subtraction = 11 Each column is subtracted to get an answer of 11…

John Owen, Rockport Fulton HS122 Subtraction, Base 10 Now look at this problem: In this problem, you need to borrow.

John Owen, Rockport Fulton HS123 Subtraction, Base Borrowing means taking a value from the next column and adding it to the column you need.

John Owen, Rockport Fulton HS124 Subtraction, Base In this case, borrow from the 6, which becomes five, and add 10 to the 3, making 13.

John Owen, Rockport Fulton HS125 Subtraction, Base When you borrow 1 from one column, it becomes the value of the base in the next column, or 10 in this case.

John Owen, Rockport Fulton HS126 Subtraction, Base Then you subtract the two columns with a result of 26.

John Owen, Rockport Fulton HS127 Subtraction, Base 8 Now let’s try base eight: Again, in this problem, you need to borrow.

John Owen, Rockport Fulton HS128 Subtraction, Base Borrow from the 6, which becomes five, and add 8 to the 3, making 11!

John Owen, Rockport Fulton HS129 Subtraction, Base When you borrow 1 from a column, it becomes the value of the base in the next column, or 8 in this case.

John Owen, Rockport Fulton HS130 Subtraction, Base Then you subtract the two columns with a result of 24, base 8.

John Owen, Rockport Fulton HS131 Subtraction, Base 16 Now base 16: Again, we borrow from the 6, which becomes five, and add 16 to the 3, making 19!

John Owen, Rockport Fulton HS132 Subtraction, Base When you borrow 1 from a column, it becomes the value of the base in the next column, or 16 in this case.

John Owen, Rockport Fulton HS133 Subtraction, Base C In the ones column, 19 minus 7 is 12, which is C in base sixteen, with 2 in the second column.

John Owen, Rockport Fulton HS134 Subtraction, Base 16 Here’s another example in base 16 D6 -3B How is this one solved? Try it.

John Owen, Rockport Fulton HS135 Subtraction, Base 16 C22 D6 -3B We must borrow from D, which becomes C, then add 16 to 6, which makes 22.

John Owen, Rockport Fulton HS136 Subtraction, Base 16 C22 D6 -3B 9B 22 minus B (11) is B. C minus 3 is 9. Answer is 9B

John Owen, Rockport Fulton HS137 Subtraction, Base 2 Now base 2: This one is easy…answer is 10

John Owen, Rockport Fulton HS138 Subtraction, Base 2 Another in base 2: Here we need to borrow from the twos place…

John Owen, Rockport Fulton HS139 Subtraction, Base Subtract to get the answer.

John Owen, Rockport Fulton HS140 Subtraction, Base 2 Still another in base 2: Now borrow again…

John Owen, Rockport Fulton HS141 Subtraction, Base Final answer is 01, base 2

John Owen, Rockport Fulton HS142 Simple Equations Here an equation to solve (base 10): x + 6 = 14

John Owen, Rockport Fulton HS143 Simple Equations Solution…subtract 6 from both sides x + 6 = x = 8

John Owen, Rockport Fulton HS144 Simple Equations Now do it in base 8: x + 6 = 14

John Owen, Rockport Fulton HS145 Simple Equations Solution…subtract 6 from both sides x + 6 = x = ?

John Owen, Rockport Fulton HS146 Simple Equations Answer is 6, base 8 12 x + 6 = x = 6

John Owen, Rockport Fulton HS147 Simple Equations Here’s an equation in base sixteen (remember, A and F are NOT variables, but base sixteen values): x + 2A = F3

John Owen, Rockport Fulton HS148 Simple Equations Solution? x + 2A = F3

John Owen, Rockport Fulton HS149 Simple Equations Subtract 2A from both sides: E19 x + 2A = F3 - 2A -2A x = C9

John Owen, Rockport Fulton HS150 Exercises Now try these exercises = = 3. F 16 - A 16 = = B 16 = 6. CC 16 - AD 16 =

John Owen, Rockport Fulton HS151 Exercises = 8. 3E 16 – 2F 16 = = = = = =

John Owen, Rockport Fulton HS152 Exercises Now let’s mix it up a bit! 14. AE = _________ = _________ F = _________ = _________ F = _________ 16

John Owen, Rockport Fulton HS153 Exercises And finally, some equations 19. x = AB x = x = x = 1F x = BAD X 16 =

John Owen, Rockport Fulton HS154 ANSWERS (JUMBLED) E 1F BF F F

155 Representing Fractional Numbers Computers store fractional numbers Negative and positive Storage technique based on floating-point notation Example: 1.345E = mantissa, E = exponent, + 5 moves decimal IEEE-754 specification Uses binary mantissas and exponents Implementation details are part of advanced study

Conversion to Decimal (d n …..d2 d 1 d 0. d -1 d -2 ……) R = ( ) 10

Examples

Example

Part5: Data Representation in Binary Binary values map to two states On or off Bit Each 1 and 0 (on and off ) in a computer Byte Group of 8 bits Word Collection of bytes (typically 4 bytes) Nibble Half a byte or 4 bits Connecting with Computer Science, 2e159

Representing Whole Numbers Whole numbers (integer numbers) Stored in fixed number of bits 2010 stored as 16-bit integer Equivalent hex value: 07DA Signed numbers stored with twos complement Leftmost bit reserved for sign 1 = negative and 0 = positive If positive: leave as is If negative: perform twos complement Reverse bit pattern and add 1 to number using binary addition 160

161 Figure 7-5, Storing numbers in a twos complement 8-bit field Representing Whole Numbers (cont’d.)

One’s Complement Way to represent negative values. Change every one in binary to zero and every zero to 1

Example Convert ( ) 2 one’s complement. ( ) 1’s Convert ( ) which is one’s complement to its binary value. ( ) 2

Two’s complement It is a way to represent a number with both value and sign. The most important property is that the Most Significant Bit has a negative weight. To convert from two’s complement to decimal is an easy way. The only difference is that during computation the weight of the last bit is negative.

Example to convert from two’s complement to decimal.

Converting from decimal number to two’s complement We have two cases. If it is a positive decimal number. It is the same as normal binary except that you add 0 as MSB to the binary number. If it is negative decimal number. Treat the number as if it is positive. Convert it to binary number. Put Zeroes to the left of the number. Convert the zero to one and one to zero for all digits Add one to the whole number.

Subtraction using two’s complement Subtraction process requires two operands: minuend and subtrahend, normally the subtrahend is greater than the minuend. Make sure you have more digits that accommodate the value of the numbers by adding zeros to the left of the two numbers. Convert the subtrahend to two’s complement. Add the two numbers. If the number of digits of the result exceeds numbers of digits both numbers. Cancel that digit.

Example of Two’s complement subtraction. Subtract 1001 from 101. Number of digits ( we need 5 digits for those numbers) so, we add trailing zeros Minuend becomes and the subtrahend becomes Convert the subtrahend to two’s complement So it becomes Add both numbers: to = As the number of digits of the result is that same as the number of the digits of both number. This is the result. (Note that as the last bit of the result is 1, it means the number is negative, to find its value. Follow the rules to convert from two’s complement to decimal)

Example of Two’s complement subtraction. Subtract 110 from Number of digits ( we need 5 digits for those numbers) so, we add trailing zeros Minuend becomes and the subtrahend becomes Convert the subtrahend to two’s complement So it becomes Add both numbers: to = Because we have six digits, the left most digits is discarded and keep the number of the digits to 5. the result will b (Note that as the last bit of the result is 0, it means the number is positive, to find its value. Follow the rules to convert from two’s complement to decimal)

John Owen, Rockport Fulton HS170 Exercises 1-5 Convert each of these to base

John Owen, Rockport Fulton HS171 Exercises Convert each of these to base A DEB C

John Owen, Rockport Fulton HS172 Exercises Convert each of these to base

John Owen, Rockport Fulton HS173 Exercises Convert each of these to base

John Owen, Rockport Fulton HS174 Exercises Convert each of these to base D BCEF A6 16

John Owen, Rockport Fulton HS175 Exercises Convert each of these to base

John Owen, Rockport Fulton HS176 Exercises Convert each of these to base

John Owen, Rockport Fulton HS177 Exercises Convert each of these to base

John Owen, Rockport Fulton HS178 Exercises Convert each of these to base

John Owen, Rockport Fulton HS179 ANSWERS…JUMBLED! F 1D5 2D 4A 9C A8 B94 BE CD EOB