Introduction to Computer Science (I1100) With 1 coin 2 possibilities: Head / Tail or 0/1

Similar documents
2 Number Systems 2.1. Foundations of Computer Science Cengage Learning

CHAPTER 2 Number Systems

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

CS & IT Conversions. Magnitude 10,000 1,

Fundamentals of Programming (C)

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

in this web service Cambridge University Press

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Chapter Binary Representation of Numbers

Number representations

CMPS 10 Introduction to Computer Science Lecture Notes

Chapter 2 Binary Values and Number Systems

Objectives. Connecting with Computer Science 2

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

Octal & Hexadecimal Number Systems. Digital Electronics

Switching Circuits and Logic Design Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Level ISA3: Information Representation

TOPIC: NUMBER SYSTEMS

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Number Systems CHAPTER Positional Number Systems

MC1601 Computer Organization

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Number Systems. Both numbers are positive

COMP Overview of Tutorial #2

Digital Systems and Binary Numbers

TOPICS. Other Number Systems. Other Number Systems 9/9/2017. Octal Hexadecimal Number conversion

T02 Tutorial Slides for Week 2

Number Systems. TA: Mamun. References: Lecture notes of Introduction to Information Technologies (ITEC 1011) by Dr Scott MacKenzie

Lecture 2: Number Systems

Digital Logic Lecture 2 Number Systems

Octal and Hexadecimal Integers

Number System. Introduction. Decimal Numbers

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

FLIPPED CLASS F#3- Number System. Department of CSE, Coimbatore CTPS 2018

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

Lecture 1: Digital Systems and Number Systems

What Is It? Instruction Register Address Register Data Register

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Section 2.3 Rational Numbers. A rational number is a number that may be written in the form a b. for any integer a and any nonzero integer b.

Review of Number Systems

Numeral system Numerals

Chapter 1 Emad Felemban

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Introduction to Numbering Systems

EE292: Fundamentals of ECE

Chapter 1 Review of Number Systems

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes

Introduction to Computers and Programming. Numeric Values

Conversion Between Number Bases

6. Binary and Hexadecimal

Common Number Systems

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Information Science 1

Internal Data Representation

Chapter 3 DATA REPRESENTATION

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

Numbers and Representations

Unit 7 Number System and Bases. 7.1 Number System. 7.2 Binary Numbers. 7.3 Adding and Subtracting Binary Numbers. 7.4 Multiplying Binary Numbers

Decimal/Binary Conversion on the Soroban

Numbering systems. Dr Abu Arqoub

LESSON TITLE. Language English Local Language Introduction to Computer Science. Mr. VAR Sovannrath Submission Date October 30th, 2014 Version 1.

Computer Organization and Assembly Language. Lab Session 01

Python Numbers. Learning Outcomes 9/19/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17

MACHINE LEVEL REPRESENTATION OF DATA

Lecture (01) Introduction Number Systems and Conversion (1)

The. Binary. Number System

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 01, SPRING 2013

Chapter 2 Exercises and Answers

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Chapter 2: Number Systems

CS321. Introduction to Numerical Methods

CHAPTER TWO. Data Representation ( M.MORRIS MANO COMPUTER SYSTEM ARCHITECTURE THIRD EDITION ) IN THIS CHAPTER

ITEC 1011 Introduction to Information Technologies

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CHAPTER 2 (b) : AND CODES

Digital Systems and Binary Numbers

Beyond Base 10: Non-decimal Based Number Systems

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

BSC & BIT Numbering Systems. ITU Lecture 3b

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Introduction to Computing Module No: CS/ES/1 Quadrant 1 e-text

CMPE223/CMSE222 Digital Logic Design. Positional representation

Chapter 1 Preliminaries

BINARY SYSTEM. Binary system is used in digital systems because it is:

Lesson 1: THE DECIMAL SYSTEM

Chapter 4 Section 2 Operations on Decimals

Korea University of Technology and Education

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

Digital Systems and Binary Numbers

CS 121 Digital Logic Design. Chapter 1. Teacher Assistant. Hadeel Al-Ateeq

Number Systems MA1S1. Tristan McLoughlin. November 27, 2013

UNIT 7A Data Representation: Numbers and Text. Digital Data

College of Computer and Information Sciences Department of Computer Science. CSC 220: Computer Organization. Unit1 Number Systems

Digital Systems COE 202. Digital Logic Design. Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals

Agenda EE 224: INTRODUCTION TO DIGITAL CIRCUITS & COMPUTER DESIGN. Lecture 1: Introduction. Go over the syllabus 3/31/2010

Learning Log Title: CHAPTER 3: ARITHMETIC PROPERTIES. Date: Lesson: Chapter 3: Arithmetic Properties

Transcription:

With 1 coin 2 possibilities: Head / Tail or 0/1 77

What if I have 2 coins?! 0 0 With 2 coins, I can have 4 possibilities 0 1 1 0 1 1 With 3 coins, I can have 2*2*2=8 possibilities With 4 coins, I can have 2 4 =16 possibilities 78

Computer architecture Number Systems 79

Outline Number systems Definitions Positional number systems Decimal system Binary system Hexadecimal system Octal system Comparison of numbers in the four systems Nonpositional number systems 80

Introduction A number system defines how a number can be represented using distinct symbols. A number can be represented differently in different systems. Example: (2A) 16 = (52) 8 = (42) 10 We use characters to create words. The number of symbols is limited. We need to repeat characters and combine then to create words. 81

Introduction It is the same for numbers. There s a limited number of symbols (digits) to represent numbers. Digits need to be repeated. 2 categories of number systems: 1. Positional 2. Non-Positional 82

274 200 + 70 + 4 2 10 2 + 7 10 1 + 4 10 0 83

15.2 10 + 5 + 0.2 1 10 1 + 5 10 0 + 2 10-1 84

Positional number systems In a positional number system, the position a symbol occupies in the number, determines the value it represents. In this system, a number represented as : ± has the value of : =± + + + + + + + + b is the base 85

Decimal system (base 10) We have 10 symbols to represent a number. The set of symbols is S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ± used to show that a number can be positive or negative. However these signs are not stored in computers (discussed in the next chapter). In the decimal system, a number is written as : ± An integer (number with no fractional part) is familiar to all of us, its value =± 10 + + 10 + 10 + 10 86

Decimal system (base 10) Another way to show an integer is to use place values, which are powers of 10 for decimal numbers. 10 10 10 10 10 Place value ± Number =± 10 + 10 + + 10 + 10 + 10 Value 87

Decimal system (base 10) Example 1 Place value of (+224) 10 in the decimal system 10 10 10 Place value + 2 2 4 Number =+ 2 10 + 2 10 + 4 10 Value 88

Decimal system (base 10) Example 2 Place value of (-7508) 10 in the decimal system 10 10 10 10 Place value 7 5 0 8 Number = (7 10 + 5 10 + 0 10 + 8 10 ) Value = (7 1000 + 5 100 + 0 10 + 8 1) Value 89

Decimal system (base 10) Reals A real (number with fractional part) is also familiar. Represented by ± Its value =± 10 + + 10 + 10 + 10 + 10 + 10 + + 10 90

Decimal system (base 10) Reals - Example 10 10 10 10 Place value + 2 4 1 3 Number =+ (2 10 + 4 1 + 1 0.1 + 3 0.01) Value 91

Binary system (base 2) The word binary is derived from the Latin root bini (or two by two) We use only 2 symbols, S = {0, 1} The symbols in this system are referred to as binary digits or bits. Data and programs are stored in the computer using a string of bits. Why? Because computer is made of electronic switches that can only have 2 states, on and off. We can represent an integer as : ± The value is calculated as =± 2 + + 2 + 2 + 2 92

Binary system (base 2) Another way to show a binary number using place values: 2 2 2 2 2 Place value ± Number =± 2 + 2 + + 2 + 2 + 2 Value 93

Binary system (base 2) Example (11001) 2 in binary is the same as 25 in decimal 2 2 2 2 2 Place value 1 1 0 0 1 Number = 1 2 + 1 2 + 0 2 + 0 2 + 1 2 Value = 16 + 8 + 0 + 0 + 1 Value 94

Binary system (base 2) Maximum value The maximum value of a binary integer with k digits is when all digits equal to 1. n max =2 k -1 Example: if k = 5, n=(11111) 2 = 2 5-1=(31) 10 95

Binary system (base 2) Reals A real (number with fractional part) is also familiar. Represented by ± Its value =± 2 + + 2 + 2 + 2 + 2 + 2 + + 2 96

Binary system (base 2) Reals - Example (101.11) 2 in binary is equal to 5.75 in decimal 2 2 2 2 2 Place value + 1 0 1 1 1 Number =+ 1 4 + 0 2 + 1 1 + 1 2 + 1 2 Value =+ 4+0+1+0.5+0.25=5.75 97

Hexadecimal system (base 16) Binary system is used in computers however it is not convenient for representation of numbers outside the computer. There s an obvious relation between binary and hexadecimal systems (as well as with octal system). We use only 16 symbols, S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} A, B, C, D, E, Fare equivalent to 10, 11, 12, 13, 14, and 15 respectively. The symbols in this system are referred to as hexadecimal digits. We can represent an integer as : ± The value is calculated as =± 16 + + 16 + 16 + 16 98

Hexadecimal system (base 16) Another way to show an hexadecimal number using place values: 16 16 16 16 16 Place value ± Number =± 16 + 16 + + 16 + 16 + 16 Value 99

Hexadecimal system (base 16) Example (2AE) 16 in hexadecimal is the equivalent to 686 in decimal 16 16 16 Place value 2 A E Number = 2 16 + 10 16 + 14 16 Value = 512 + 160 + 14 Value 100

Hexadecimal system (base 16) Maximum value The maximum value of an hexadecimal integer with k digits is equal to n max =16 k -1 Example: if k = 5, n=16 5-1=(1 048 575) 10 It is not common to represent real numbers in hexadecimal. We leave it as an exercise. 101

Octal system (base 8) Devised to show the equivalent of the binary system outside the computer. We use only 8 symbols, S = {0, 1, 2, 3, 4, 5, 6, 7} The symbols in this system are referred to as octal digits. We can represent an integer as : ± The value is calculated as =± 8 + + 8 + 8 + 8 102

Octal system (base 8) Another way to show an octal number using place values: 8 8 8 8 8 Place value ± Number =± 8 + 8 + + 8 + 8 + 8 Value 103

Octal system (base 8) Example (1256) 8 in octal is the equivalent to 686 in decimal 8 8 8 8 Place value 1 2 5 6 Number = 1 8 + 2 8 + 5 8 + 6 8 Value = 512 + 128 + 40 + 6 Value 104

Octal system (base 8) Maximum value The maximum value of an octal integer with k digits is equal to n max =8 k -1 Example: if k = 5, n=8 5-1=(32767) 10 It is not common to represent real numbers in octal. We leave it as an exercise. 105

Summary of the four positional systems System Base Symbols Example Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 2345.56 Binary 2 0, 1 (1001.11) 2 Octal 8 0, 1, 2, 3, 4, 5, 6, 7 (156.23) 8 Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (A2C.A1) 16 106

Comparison of numbers in the Decimal, Binary and Octal systems Decimal Binary Octal 0 000 0 1 001 1 2 010 2 3 011 3 4 100 4 5 101 5 6 110 6 7 111 7 107

Comparison of numbers in the four systems Decimal Binary Octal Hexadecimal 0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F 108

Conversion Need to know how to convert a number in one system to the equivalent number in another system. We first show how to convert from any base to decimal. Then we show how to convert from decimal to any base. Then, we show how to convert from binary to hexadecimal or octal and vice versa. 109

Conversion from base b to decimal To convert: multiply each digit with its place value in the source system and add the results to get the number in the decimal system. Decimal point System b b b b Place value + + + + + + + Mutiplication Integral Fraction Decimal 110

Conversion Example 1 Convert the binary number (110.11) 2 to decimal. (110.11) 2 = 6.75 Binary 1 1 0 1 1 Place Value 2 2 2 2 2 Partial result 4 + 2 + 0 + 0.5 + 0.25 Decimal 6.75 111

Conversion Example 2 Convert the hexadecimal number (1A.23) 16 to decimal. Hexadecimal 1 A 2 3 Place Value 16 16 16 16 Partial result 16 + 10 + 0.125 + 0.012 Decimal 26.137 =0.1171875 (1A.23) 16 26.137 112

Conversion Example 3 Convert the octal number (23.17) 8 to decimal. Octal 2 3 1 7 Place Value 8 8 8 8 Partial result 16 + 3 + 0.125 + 0.109 Decimal 19.234 =0.109375 (23.17) 8 19.234 113

Conversion from decimal to base b We can convert a decimal number to its equivalent in any base: We need 2 procedures: 1. One for the integral part 2. One for the fractional part 114

Converting the integral part Done by repetitive division. Source number Remainders Quotients Divide by destination base 0 Q Q Q S R R R R D Destination number Destination digits 115

Converting the integral part Example 1 Convert 35 in decimal to binary (base 2) Divide by 2 0 1 2 4 8 17 35 D 1 0 0 0 1 1 35 = (100011) 2 116

Converting the integral part Example 2 Convert 126 in decimal to octal 0 1 15 126 1 7 6 126= (176) 8 117

Converting the integral part Example 3 Convert 126 in decimal to hexadecimal 0 7 126 7 126= (7E) 16 118

Converting the fractional part Done by repetitive multiplication. Source number Integral part Fractional part Multiply by destination base S F F F 0 I I I I Destination number Destination digits 119

Converting the fractional part Convert the decimal number 0.625 to binary 0.625 0.25 0.50 0 I I I 1 0 1 0.625= (0.101) 2 120

Converting the fractional part Convert the decimal number 0.634 to octal (with a maximum of 4 digits) 0.634 0.072 0.576 0.608 0.864 I I I I 5 0 4 4 0.634= (0.5044) 8 121

Converting the fractional part Convert the decimal number 178.6 to hexadecimal 178.6= (B2.9) 16 0 11 178 0.6 0.6 2 9 122

Number of digits In a base b, we can find the number of digits of an integer using = log means the smallest integer greater than or equal to Example: find the required number of bits in the decimal number 234 in all four systems In decimal = log 234 = 2.37 =3 In binary = log 234 = 7.8 =8(because 234=(11101010) 2 ) In octal = log 234 = 2.62 =3(because 234=(352) 8 ) In hexadecimal = log 234 = 1.96 =2(because 234=(EA) 16 ) 123

Binary hexadecimal conversion 4 bits in binary is one digit in hexadecimal B m B m-1 B m-2 B m-3 B 7 B 6 B 5 B 4 B 3 B 2 B 1 B 0 Binary H n H 1 H 0 Hexadecimal 124

Binary hexadecimal conversion Example Show the hexadecimal equivalent of the binary number (10011100010) 2 We arrange the binary number in 4-bit patterns: 100 1110 0010 The leftmost patter can have 1 to 4 bits Change the number to hexadecimal (100 1110 0010) 2 = (4E2) 16 125

Binary hexadecimal conversion Example What s the binary equivalent of (24C) 16 Each hexadecimal digit is converted to 4-bit patterns: 2 0010 4 0100 C 1100 The result (0010 0100 1100) 2 126

Binary octal conversion 3 bits in binary is one octal digit B m B m-1 B m-2 B 5 B 4 B 3 B 2 B 1 B 0 Binary O n O 1 O 0 Octal 127

Binary octal conversion Example Show the octal equivalent of the binary number (101110010) 2 We arrange the binary number in 3-bit patterns: 101 110 010 Change the number to octal (101 110 010) 2 = (562) 8 128

Binary octal conversion Example What s the binary equivalent of (24) 8 Each octal digit is converted to 3-bit patterns: 2 010 4 100 The result (010 100) 2 129

Hexadecimal Binary Octal conversion 3 bits in binary is one octal digit 4 1 1 6 Octal 1 0 0 0 0 1 0 0 1 1 1 0 Binary 8 4 E Hexadecimal 130

Nonpositional number systems Nonpositional number systems are not used in computers. Uses a limited number of symbols in which each symbol has a value. The position a symbol occupies in the number normally bears no relation to its value 131

Nonpositional number systems Roman numerals S={I, V, X, L, C, D, M} Symbol I V X L C D M Value 1 5 10 50 100 500 1000 To find the value of a number: 1. When a symbol with smaller value is placed after a symbol having an equal or larger value, the values are added. 2. When a symbol with smaller value is placed before a symbol having a larger value, the smaller value is subtracted from the larger one. 3. A symbol S 1 cannot come before another symbol S 2 if S 1 10* S 2. Example: I or V cannot come before C. 132

Nonpositional number systems Roman numerals - Examples III 1+1+1 = 3 IV 5-1 = 4 VIII 5+1+1+1=8 XVIII 10+5+1+1+1=18 XIX 10+(10-1)=19 LXXII 50+10+10+1+1=72 CI 100+1=101 MMVII 1000+1000+5+1+1=2007 MDC 1000+500+100=1600 133

References Foundations of Computer Science Behrouz A. Forouzan, Firouz Mosharraf 134

Upcoming lecture number Character typed on keyboard Part of an image Part of a song Part of a film 65 A Program Math routine Program Text editor Program Image recorder Program Music recorder Program Video recorder 01000001 Memory 01000001 Memory 01000001 Memory 01000001 Memory 01000001 Memory 145