MACHINE LEVEL REPRESENTATION OF DATA

Similar documents
IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

COMP Overview of Tutorial #2

Digital Fundamentals

CHW 261: Logic Design

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

Computer Organization

Final Labs and Tutors

Chapter 1 Review of Number Systems

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Number System. Introduction. Decimal Numbers

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

Module 2: Computer Arithmetic

Number Systems CHAPTER Positional Number Systems

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

COMP2121: Microprocessors and Interfacing. Number Systems

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

Chapter 2. Data Representation in Computer Systems

Number Systems. Both numbers are positive

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

CS & IT Conversions. Magnitude 10,000 1,

Chapter 4: Computer Codes. In this chapter you will learn about:

Objectives. Connecting with Computer Science 2

The type of all data used in a C++ program must be specified

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

Number representations

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Binary Codes. Dr. Mudathir A. Fagiri

Review of Number Systems

Numeric Encodings Prof. James L. Frankel Harvard University

Introduction to Numbering Systems

Introduction to Computers and Programming. Numeric Values

World Inside a Computer is Binary

Digital Computers and Machine Representation of Data

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Chapter 4: Data Representations

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

CHAPTER 5: Representing Numerical Data

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Numbering systems. Dr Abu Arqoub

Number Systems & Encoding

CHAPTER 2 Data Representation in Computer Systems

CMPE223/CMSE222 Digital Logic Design. Positional representation

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

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

D I G I T A L C I R C U I T S E E

Lecture 2: Number Systems

Binary. Hexadecimal BINARY CODED DECIMAL

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

CS 101: Computer Programming and Utilization

Chapter 2 Data Representations

SE311: Design of Digital Systems

Inf2C - Computer Systems Lecture 2 Data Representation

Organisasi Sistem Komputer

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Signed Binary Numbers

CHAPTER 2 Data Representation in Computer Systems

Data Representations & Arithmetic Operations

Electronic Data and Instructions

Announcement. (CSC-3501) Lecture 3 (22 Jan 2008) Today, 1 st homework will be uploaded at our class website. Seung-Jong Park (Jay)

DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Data Representation. DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

DIGITAL SYSTEM DESIGN

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

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

M1 Computers and Data

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

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

Chap 1. Digital Computers and Information

LOGIC DESIGN. Dr. Mahmoud Abo_elfetouh

Thus needs to be a consistent method of representing negative numbers in binary computer arithmetic operations.

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

QUIZ ch.1. 1 st generation 2 nd generation 3 rd generation 4 th generation 5 th generation Rock s Law Moore s Law

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary 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 TWO. Data Representation ( M.MORRIS MANO COMPUTER SYSTEM ARCHITECTURE THIRD EDITION ) IN THIS CHAPTER

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

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Microcomputers. Outline. Number Systems and Digital Logic Review

CHAPTER 2 (b) : AND CODES

Divide: Paper & Pencil

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Level ISA3: Information Representation

Lecture (02) Operations on numbering systems

Digital Fundamentals

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

COMP2611: Computer Organization. Data Representation

Digital Logic Lecture 2 Number Systems

Chapter 2 Number Systems and Codes Dr. Xu

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

CO212 Lecture 10: Arithmetic & Logical Unit

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Number Systems Base r

Transcription:

MACHINE LEVEL REPRESENTATION OF DATA CHAPTER 2 1

Objectives Understand how integers and fractional numbers are represented in binary Explore the relationship between decimal number system and number systems of other bases (binary, octal, hexadecimal) Understand signed numbers and unsigned numbers Understand number representations in two s complement Perform arithmetic operations in every base Understand the method of floating point number representation in IEEE format 2

Introduction NUMBERING SYSTEM : BASE DECIMAL BINARY OCTAL HEXA- DECIMAL 5 TH PLACE 4 TH PLACE 3 RD PLACE 2 ND PLACE 1 ST PLACE PLACE SINGLE UNIT 1 ST PLACE 2 ND PLACE 10 5 10 4 10 3 10 2 10 1 10 0 10-1 10-2 10-3 3 RD PLACE 100,000 10,000 1,000 100 10 1 0.1 0.01 0.001 1/10 1/100 1/1000 2 5 2 4 2 3 2 2 2 1 2 0 2-1 2-2 2-3 32 16 8 4 2 1 0.5 0.25 0.125 1/2 1/4 1/8 8 5 8 4 8 3 8 2 8 1 8 0 8-1 8-2 8-3 32,768 4,096 512 64 8 1 0.125 0.015625 1.953125 X 10 3 1/8 1/64 1/512 16 5 16 4 16 3 16 2 16 1 16 0 16-1 16-2 16-3 1,048,57 3.906 X 2.441406 65,536 4,096 256 16 1 0.0625 6 10 3 2 X 10 4 1/16 1/256 1/4096 3

Arithmetic Operations in Different Number Bases The following table shows the equivalent values for decimal numbers in binary, octal and hexadecimal: 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 4

Number Bases Radix : when referring to binary, octal, decimal, hexadecimal, a single lowercase letter appended to the end of each number to identify its type. E.g. hexadecimal 45 will be written as 45h octal 76 will be written as 76o or 76q binary 11010011 will be written as 11010011b 5

Number Bases Decimal system: system of positional notation based on powers of 10. Binary system: system of positional notation based powers of 2 Octal system: system of positional notation based on powers of 8 Hexadecimal system: system of positional notation based on powers of 16 6

Why Binary? Early computer design was decimal Mark I and ENIAC John von Neumann proposed binary data processing (1945) Simplified computer design Used for both instructions and data Natural relationship between on/off switches and calculation using Boolean logic On Off True False Yes No 1 0 7

Binary Numbers A computer stores both instructions and data as individual electronic charges. represent these entities with numbers requires a system geared to the concept of on and off or true and false Binary is a base 2 numbering system each digit is either a 0 (off) or a 1 (on) Computers store all instructions and data as sequences of binary digit e.g. 010000010100001001001000011 = ABC 8

Binary Numbers Bit : each digit in a binary number Byte : consists of 8 bits which is the basic unit of storage on nearly all computers Each location in the computer s memory holds exactly 1 byte or 8 bits. A byte can hold a single instruction, a character or a number A Word : which is 16 bits or 2 bytes long : byte 1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 word byte A 16-bit computer : its instructions can operate on 16-bit quantities 9 bit

Numeric Data Representation FOR DECIMAL 43 = 4 x 10 1 + 3 x 10 0 10 s place 1 s place Place 10 1 10 0 Value 10 1 Evaluate 4 x 10 3 x1 Sum 40 3 10

Numeric Data Representation FOR DECIMAL 527 = 5 x 10 2 + 2 x 10 1 + 7 x 10 0 100 s place 10 s place 1 s place Place 10 2 10 1 10 0 Value 100 10 1 Evaluate 5 x 100 2 x 10 7 x1 Sum 500 20 7 11

Numeric Data Representation 624 8 = 404 10 64 s place 8 s place 1 s place Place 8 2 8 1 8 0 Value 64 8 1 Evaluate 6 x 64 2 x 8 4 x 1 Sum for Base 10 384 16 4 12

Numeric Data Representation 6,704 16 = 26,372 10 4,096 s place 256 s place 16 s place 1 s place Place 16 3 16 2 16 1 16 0 Value 4,096 256 16 1 Evaluate 6 x 4,096 7 x 256 0 x 16 4 x 1 Sum for Base 10 24,576 1,792 0 4 13

Numeric Data Representation 1101 0110 2 = 214 10 Place 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Value 128 64 32 16 8 4 2 1 Evaluate 1 x 128 1 x 64 0 x 32 1 x16 0 x 8 1 x 4 1 x 2 0 x 1 Sum for Base 10 128 64 0 16 0 4 2 0 14

Base or Radix Base: The number of different symbols required to represent any given number The larger the base, the more numerals are required Base 10 : 0,1, 2,3,4,5,6,7,8,9 Base 2 : 0,1 Base 8 : 0,1,2, 3,4,5,6,7 Base 16 : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F 15

Number of Symbols vs Number of Digits For a given number, the larger the base the more symbols required but the fewer digits needed Example #1: 65 16 101 10 145 8 110 0101 2 Example #2: 11C 16 284 10 434 8 1 0001 1100 2 16

Numeric Conversion between Number Bases Decimal Other bases Other bases Decimal Binary Octal Binary Hexadecimal Octal Binary Hexadecimal Binary 17

CONVERSION : DECIMAL OTHER BASES 18

From Base 10 to Base 2 Base 10 42 Remainder Quotient 2 ) 42 ( 0 Least significant bit 2 ) 21 ( 1 2 ) 10 ( 0 2 ) 5 ( 1 2 ) 2 ( 0 2 ) 1 ( 1 Most significant bit 0 Base 2 101010 19

From Base 10 to Base 2 Convert 37 10 to binary. 37 2 = 18 balance 1 (LSB) 18 2 = 9 balance 0 9 2 = 4 balance 1 4 2 = 2 balance 0 2 2 = 1 balance 0 1 2 = 0 balance 1 (MSB) Therefore, 37 10 = 100101 2 * MSB (most-significant-bit) : left most bit LSB (least-significant-bit) : right most bit 20

From Base 10 (decimal point) to Base 2 What is the value of 37.6875 10 in binary? Steps : 1. Convert the integer to binary by using method shown in previous slide. 2. Convert the decimal point to binary by using the following method. 0.6875 X 2 (MSB) 1 1.3750 X 2 0 0.7500 X 2 1 1.5000 X 2 (LSB) 1 1.0000 The 1 is saved as result, then dropped and the process repeated So, (0.6875) 10 = (0.1011) 2 ; Therefore, 37.6875 10 = 100101.1011 2 21

From Base 10 to Base 8 Base 10 135 Remainder Quotient 8) 135 ( 7 Least significant bit 8) 16 ( 0 8) 2 ( 2 Most significant bit 0 Base 8 207 22

From Base 10 (decimal point) to Base 8 Convert 21.25 10 to octal. 8 21 5 8 2 2 0 0.25 x 8 2 2.00 Therefore, 21.25 10 = 25.2 8 23

From Base 10 (decimal point) to Base 8 Convert 21.25 10 to octal. (OTHER METHOD) 21 2 = 10 balance 1 (LSB) 10 2 = 5 balance 0 5 2 = 2 balance 1 2 2 = 1 balance 0 1 2 = 0 balance 1 (MSB) So, 21 10 = 10101 2 Therefore, Refer to conversion of binary to hexadecimal 21.25 10 = 010 101. 010 2 = 25.2 8 Now, 0.25 X 2 (MSB) 0 0.50 X 2 (LSB) 1 1.00 So, 0.25 10 = 0.01 2 24

From Base 10 to Base 16 Base 10 5,735 Remainder Quotient 16 ) 5,735 ( 7 Least significant bit 16 ) 358 ( 6 16 ) 22 ( 6 16 ) 1 ( 1 Most significant bit 0 Base 16 1667 25

From Base 10 to Base 16 Base 10 8,039 Remainder Quotient 16 ) 8,039 ( 7 Least significant bit 16 ) 502 ( 6 16 ) 31 ( 15 16 ) 1 ( 1 Most significant bit 0 Base 16 1F67 26

From Base 10 to Base 16 Convert 21 10 to hexadecimal. 21 16 = 1 balance 5 (LSB) 1 16 = 0 balance 1 (MSB) Therefore, 21 10 = 15 16 27

From Base 10 (decimal point) to Base 16 Convert 21.25 10 to hexadecimal. 16 21 5 16 1 1 0 0.25 x 16 4 4.00 Therefore, 21.25 10 = 15.4 16 28

From Base 10 (decimal point) to Base 16 Convert 21.25 10 to hexadecimal. (OTHER METHOD) 21 2 = 10 balance 1 (LSB) 10 2 = 5 balance 0 5 2 = 2 balance 1 2 2 = 1 balance 0 1 2 = 0 balance 1 (MSB) So, 21 10 = 10101 2 Therefore, Refer to conversion of binary to hexadecimal 21.25 10 = 10101. 0100 2 = 15.4 16 Now, 0.25 X 2 (MSB) 0 0.50 X 2 (LSB) 1 1.00 So, 0.25 10 = 0.01 2 29

CONVERSION : OTHER BASES DECIMAL 30

From Base 2 to Base 10 Convert 100110 2 to decimal. 1 0 0 1 1 0 2 5 2 4 2 3 2 2 2 1 2 0 32 16 8 4 2 1 1*32 1*4 1*2 32 + 4 + 2 = 38 10 100110 2 = (1 X 2 5 ) + (0 X 2 4 ) +(0 X 2 3 ) +(1 X 2 2 ) + (1 X 2 1 ) + (0 X 2 0 ) = 32 + 0 + 0 + 4 + 2 + 0 = 38 10 Therefore, 100110 2 = 38 10 31

From Base 16 to Base 10 Convert E5 16 to decimal. E 5 16 1 16 0 16 1 14*16 5*1 224 + 5 = 229 10 E5 16 = (E X 16 1 ) + (5 X 16 0 ) = (14 X 16) + (5 X 1) = 224 + 5 = 229 10 Therefore, E5 16 = 229 10 32

From Base 16 (decimal point) to Base 10 Convert E5.A8 16 to decimal. E 5. A 8 16 1 16 0. 16-1 16-2 16 1. 0.0625 0.00390625 14*16 5*1. 10*0.0625 8*0.00390625 224 + 5 + 0.625 + 0.03125 = 229.65625 10 33

From Base 16 (decimal point) to Base 10 Convert E5.A8 16 to decimal. (OTHER METHOD) 1. Firstly convert the number into binary, Hex E 5. A 8 Binary 1110 0101. 1010 1000 2. From Example 15: E5 16 = 229 10 3. Now, (0.1010 1000) 2 = (1 X 2-1 ) + (0 X 2-2 ) + (1 X 2-3 ) + (0 X 2-4 ) + (1 X 2-5 ) + (0 X 2-6 ) + (0 X 2-7 ) + (0 X 2-8 ) = 1/2 + 1/2 3 + 1/2 5 = 1/2 + 1/8 + 1/32 = 0.5 + 0.125 + 0.03125 = (0.65625) 10 Therefore, E5.A8 16 = 229.65625 10 34

From Base 8 to Base 10 Convert 7263 8 to decimal. 7 2 6 3 8 3 8 2 8 1 8 0 512 64 8 1 7*512 2*64 6*8 3*1 3584 + 128 + 48 + 3 = 3763 10 35

From Base 8 to Base 10 7263 8 = 3,763 10 (OTHER METHOD) 7 x 8 56 + 2 = 58 x 8 464 + 6 = 470 x 8 3760 + 3 = 3,763 36

From Base 8 (decimal point) to Base 10 Convert 46.32 8 to decimal. 4 6. 3 2 8 1 8 0. 8-1 8-2 8 1. 0.125 0.015625 4*8 6*1. 3*0.125 2*0.015625 32 + 6 + 0.375 + 0.03125 = 38.40625 10 37

CONVERSION : BINARY HEXADECIMAL BINARY OCTAL 38

From Base 16 to Base 2 The nibble approach Hex easier to read and write than binary Why hexadecimal? Modern computer operating systems and networks present variety of troubleshooting data in hex format The relationship between BINARY and HEXADECIMAL 1 digit hexadecimal is EQUIVALENT to 4 bits binary Base 16 1 F 6 7 Base 2 0001 1111 0110 0111 39

From Base 16 to Base 2 Method: Get the binary representation for the hexadecimal number. Example: Convert F1 16 to binary. F1 16 = F 1 1111 0001 2 F1 16 = 1111 0001 2 40

From Base 16 to Base 2 (decimal point) Method: Get the binary representation for the hexadecimal number. Example: Convert 2A.5C 16 to binary. 2A.5C 16 = 2 A. 5 C 0010 1010. 0101 1100 2A.5C 16 = 10 1010. 0101 11 2 41

From Base 2 to Base 16 Method: Find the hexadecimal representation for the GROUP of 4 binary numbers. Example: Convert 1100111 2 to hexadecimal number. 110 0111 2 = 0110 0111 6 7 1100111 2 = 67 16 42

From Base 2 to Base 16 (decimal point) Method: Find the hexadecimal representation for the GROUP of 4 binary numbers. Use the decimal point as your STARTING point. Example: Convert 111110.00101 2 to hexadecimal number. 11 1110.0010 1 2 = 0011 1110. 0010 1000 3 E. 2 8 111110.00101 2 = 3E.28 16 43

From Base 8 to Base 2 The relationship between BINARY and OCTAL 1 digit octal is EQUIVALENT to 3 bits binary Base 8 1 2 5 7 Base 2 001 010 101 111 44

From Base 8 to Base 2 Method: Get the binary representation for every digit in the octal number. Example 17: Convert 53 8 to binary. 53 8 = 5 3 101 011 2 53 8 = 101011 2 45

From Base 8 to Base 2 (decimal point) Method: Get the binary representation for every digit in the octal number. Example 17: Convert 27.64 8 to binary. 27.64 8 = 2 7. 6 4 010 111. 110 100 27.64 8 = 10 111. 110 1 2 46

From Base 2 to Base 8 Method: Find the octal representation for the GROUP of 3 binary numbers. Example: Convert 1100111 2 to octal number. 1 100 111 2 = 001 100 111 1 4 7 1100111 2 = 147 8 47

From Base 2 to Base 8 (decimal point) Method: Find the octal representation for the GROUP of 3 binary numbers. Use the decimal point as your STARTING point. Example: Convert 11110.00101 2 to octal number. 11 110.001 01 2 = 011 110. 001 010 3 6. 1 2 11110.00101 2 = 36.12 8 48

ADDITION AND SUBTRACTION OF DIFFERENT BASES 49

Addition Base Problem Largest Single Digit Decimal Octal Hexadecimal Binary 6 +3 6 +1 6 +9 1 +0 9 7 F 1 50

Addition and Subtraction of Binary Numbers Example ADD 1 1 1 1 1 1 1 0 1 1 1 1 0 0 + 1 1 0 0 1 1 1 1 1 1 0 0 0 1 0 1 1 Example SUB 0 2 0 1 1 1 2 1 1 1 0 0 0 0 1-1 0 1 0 1 1 1 0 1 1 0 1 1 0 51

Addition of Octal Numbers Example ADD 1 1 1 3 3 3 3 + 6 = 9 8 = 1 + 4 7 6 1 + 3 + 7 = 11 8 = 3 1 0 3 1 1 + 3 + 4 = 8 8 = 0 1 + 0 = 1 52

Subtraction of Octal Numbers Example SUB 6 8 1 8 7 2 3 8 + 3 6 = 5-5 3 6 8 + 1 3 = 6 1 6 5 6 5 = 1 53

Addition of Hexadecimal Numbers Example ADD 1 1 A 2 3 3 + 8 = 11 = B + 7 C 2 8 2 + 2 = 4 9 6 4 B 10 + 12 = 22 16 = 6 1 + 1 + 7 = 9 54

Subtraction of Hexadecimal Numbers Example SUB E 16 6 16 2 F 7 D 16 + 13 14 = 15 = F - 9 E 16 + 6 9 = 13 = D 2 E D F E 0 = E 2 0 = 2 55

THE ALPHANUMERIC REPRESENTATION 56

The Alphanumeric Representation The data entered as characters, number digits, and punctuation are known as alphanumeric data. 3 alphanumeric codes are in common use. ASCII (American Standard Code for Information Interchange) Unicode EBCDIC (Extended Binary Coded Decimal Interchange Code). 57

The Alphanumeric Representation The following tables show the comparisons between the ASCII code in binary and hexadecimal for the given characters. Character Binary Hex A 100 0001 41 B 100 0010 42 C 100 0011 43 D 100 0100 44 E 100 0101 45 F 100 0110 46 G 100 0111 47 H 100 1000 48 I 100 1001 49 J 100 1010 4A K 100 1011 4B Space 010 0000 20 Full stop 010 1110 2E ( 010 1000 28 + 010 1011 2B $ 010 0100 24 58

THE DECIMAL REPRESENTATION 59

The Decimal Representation BCD (Binary Coded Decimal) is often used to represent decimal number in binary. Decimal BCD 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 60

SIGNED AND UNSIGNED NUMBERS 61

Signed and Unsigned Numbers Binary numbers may either signed or unsigned Oddly, CPU performs arithmetic and comparison operations for both type equally well, without knowing which type it s operating on. An unsigned numbers : numbers with only positive values for 8-bit storage location : store unsigned integer value between 0-255 for 16-bit storage location : store unsigned integer value between 0-65535 Unsigned number can be converted directly to binary numbers and processed without any special care 62

Signed and Unsigned Numbers For negative numbers, there are several ways used to represent it in binary form, depending on the process take place : i. Sign-and-magnitude representation ii. 1 s complement representation iii. 2 s complement representation 63

Sign-and-Magnitude In daily usage, signed integers are represented by a plus or minus sign and a value. In the computer, the uses of 0 s and 1 s take place. 0 : plus ( positive) 1 : minus (negative) The leftmost bit in a binary number is considered the sign bit. The remaining (n-1) bits are used for magnitude. 64

Sign-and-Magnitude Example 1 : + 0010 0101 (+37) - 1010 0101 (-37) 0000 0000 0000 0001 (+1) 1000 0000 0000 0001 (-1) 0111 1111 1111 1111 (+32767) 1111 1111 1111 1111 (-32767) 65

Sign-and-Magnitude Example 2 : What is the sign-and-magnitude representation of the decimal numbers 31 and +31 if the basic unit is a byte? 31 10 = 11111 2 Unit is a byte = 8 bits +31 = 0 0 0 1 1 1 1 1-31 = 1 0 0 1 1 1 1 1 66

Sign-and-Magnitude Example 3 : What is the sign-and-magnitude representation of the decimal numbers 31 and +31 if the basic unit is a word? 31 10 = 11111 2 Unit is a word= 16 bits +31 = 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1-31 = 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 67

Sign-and-Magnitude Example 4 : What is the decimal equivalent value of the sign-and -magnitude binary sequence 1011 1001? 1 0 1 1 1 0 0 1 Sign is negative 11 1001 2 = 57 10 1011 1001 2 = - 57 10 68

Sign-and-Magnitude Addition of 2 numbers in sign-and-magnitude : using the usual conventions of binary arithmetic if both have same sign : magnitude are added and the same sign copied if the sign different : number that has smaller magnitude is subtracted from the larger one. The sign is copied from the larger magnitude. 69

Sign-and-Magnitude Example 5 : What is the decimal value of the sum of the binary numbers 00100110 and 00011110 if they are represented in sign-and-magnitude? Assume that the basic unit is the byte. Same signs : magnitude are added 1 1 1 1 1 0 0 1 0 0 1 1 0 + 0 0 0 1 1 1 1 0 0 1 0 0 0 1 0 0 Sign is positive 100 0100 2 = 68 10 0100 0100 2 = +68 10 70

Sign-and-Magnitude Example 6 : What is the decimal value of the sum of the binary numbers 10110011 and 00010110 if they are represented in sign-and-magnitude? Assume that the basic unit is the byte. Different signs : Larger magnitude - smaller magnitude Larger magnitude : 1011 0011 Smaller magnitude : 0001 0110 2 0 0 1 2 1 0 1 1 0 0 1 1-0 0 0 1 0 1 1 0 1 0 0 1 1 1 0 1 Sign is negative 11101 2 = 29 10 1001 1101 2 = - 29 10 71

1 S Complement Convention In base 2, the largest digit is 1. The 1 s complement is performed simply by changing: every 0 1 and every 1 0. Also known as inversion 72

2 S Complement Convention Most popular among computer manufacturers since it does not present any of the problems of the sign-and-magnitude or 1 s complement. Positive numbers : using similar procedure as sign-and-magnitude Given n bits, the range of numbers that can be represented in 2 s complement is ( (2 n )) to (2 n-1 1) 0111 1111 0000 0000 1111 1111 1000 0000 (127) (0) (-1) (-128) ( 2 n-1 1) - (2 n ) Notice that the range of negative numbers is one larger than the range of the positive values 73

2 S Complement Convention To represent a negative number in this convention, follow the 3 steps process below: Step 1 : Express the absolute value of the number in binary Step 2 : Change all 0s to 1s and vise versa 1 s complement Step 3 : Add 1 to the binary number of step 2 Example 1 : What is the 2 s complement representation of -23? Example 2 : What is the decimal positive value of the 2 s complement number 11100011? 74

2 S Complement Convention Example 1 : What is the 2 s complement representation of -23? Step: 23 in binary 0 0 0 1 0 1 1 1 1 s (inverse) 1 1 1 0 1 0 0 0 2 s + 1 2 s complement representation 1 1 1 0 1 0 0 1 75

2 S Complement Convention Example 2 : What is the decimal positive value of the 2 s complement number 11100011? Step: 2 s complement representation 1 1 1 0 0 0 1 1 1 s (inverse) 0 0 0 1 1 1 0 0 2 s + 1 Decimal positive value 0 0 0 1 1 1 0 1 76

The IEEE Floating Point Representation 2 problems with integers; They can t express fractions, AND The range number is limited to the number of bits used. An efficient way of storing fractions floating point method involves splitting the fraction into two parts, an exponent and a mantissa Computer industry agreed upon a standard for the storage of floating point numbers the IEEE 754 standard; uses 32 bits of memory (single precision) or 64 bits (double precision) 77

The IEEE Floating Point Representation IEEE short real : 32 bits (Exponent system = excess 127) Total number of bits : 1 8 23 Sign Biased exponent Mantissa (fraction) IEEE short real : 64 bits (Exponent system = excess 1023) Total number of bits : 1 11 52 Sign Biased exponent Mantissa (fraction) 78

The IEEE Floating Point Representation Convert 153.75 10 to the IEEE floating point format. Step 1 : convert into binary Step 2 : put into 1.xxxx X 2 y format Step 3 : get the biased exponent Step 4 : get the sign (from the question) Step 5 : identify significand and mantissa Step 6 : put into the IEEE single precision format Step 7 : convert into hexadecimal 79

The IEEE Floating Point Representation Convert to binary 153.75 = 1001 1001.11 2 Put into 1.xxxx X 2 y = 1.0011 0011 1 2 x 2 7 Biased exponent Exponent = 7 Biased exponent = 127 + y = 127 + 7 = 134 = 1000 0110 2 (8 bits) Sign Sign = +ve (0) Significand Mantissa Significand = 1.0011 0011 1 Mantissa = 001 1001 1100 0000 0000 0000 (23bits) IEEE format : IEEE format Sign Biased Exponent Mantissa (23) 0 1000 0110 001 1001 1100 0000 0000 0000 0100 0011 0001 1001 1100 0000 0000 0000 Hexadecimal 4 3 1 9 C 0 0 0 = 4319 C000 h 80

Eg: Convert -29 / 128 10 The IEEE Floating Point Representation Convert to binary 29 / 128 = 11101 2 / 2 7 = 11101 2 x 2-7 Put into 1.xxxx X 2 y = 1.1101 2 x 2 4 x 2-7 = 1.1101 2 x 2-3 Biased exponent Exponent = -3 Biased exponent = 127 + y = 127 + (-3) = 124 = 0111 1100 2 (8 bits) Sign Sign = -ve = 1 Significand Mantissa Significand = 1.1101 Mantissa = 110 1000 0000 0000 0000 0000 (23bits) IEEE format : IEEE format Sign Biased Exponent Mantissa (23) 1 0111 1100 110 1000 0000 0000 0000 0000 1011 1110 0110 1000 0000 0000 0000 0000 Hexadecimal B E 6 8 0 0 0 0 = BE68 0000 h 81

The IEEE Floating Point Representation Convert C2F0 0000 16 in IEEE floating point format to the decimal number. Step 1 : in hexadecimal Step 2 : convert into binary Step 3 : put into the IEEE single precision format Step 4 : get biased exponent Step 5 : get the sign Step 6 : identify significand and mantissa Step 7 :put into 1.xxxx X 2 y Step 8 : identify actual number 82

The IEEE Floating Point Representation In hexadecimal C2F00000 16 Convert to binary C 2 F 0 0 0 0 0 1100 0010 1111 0000 0000 0000 0000 0000 Put into IEEE format Get the biased exponent Sign Mantissa Significand Put into 1.xxxx X 2 y IEEE format : Sign Biased Exponent Mantissa (23) 1 1000 0101 111 0000 0000 0000 0000 0000 Biased Exponent:: 1000 0101 = 133 Exponent : 133 127 = 6 1 = -ve 111 0000 0000 0000 0000 0000 1.111 1.111 x 2 6 =1111 000 2 = 120 10 The actual number - 120 83