Chapter 2 Data Types and Representations

Slides:



Advertisements
Similar presentations
CHAPTER 2 Number Systems, Operations, and Codes
Advertisements

Digital Fundamentals Floyd Chapter 2 Tenth Edition
Data Representation Computer Organization &
Data Representation COE 205
Data Representation ICS 233
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Simple Data Type Representation and conversion of numbers
1 Data Representation Computer Organization Prof. H. Yoon DATA REPRESENTATION Data Types Complements Fixed Point Representations Floating Point Representations.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Data Representation – Binary Numbers
Computers Organization & Assembly Language
Digital Design: From Gates to Intelligent Machines
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
Dept. of Computer Science Engineering Islamic Azad University of Mashhad 1 DATA REPRESENTATION Dept. of Computer Science Engineering Islamic Azad University.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Chapter 2 Number Systems + Codes. Overview Objective: To use positional number systems To convert decimals to binary integers To convert binary integers.
Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.
Figure 1.1 Block diagram of a digital computer. Functional Units.
1 EENG 2710 Chapter 1 Number Systems and Codes. 2 Chapter 1 Homework 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a, 1.19.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
AEEE2031 Data Representation and Numbering Systems.
1 Information Representation in Computer Lecture Nine.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
CS 2130 Lecture 23 Data Types.
Systems Architecture, Fourth Edition 1 Data Representation Chapter 3.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
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.
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
PRIMITIVE TYPES IN JAVA Primitive Types Operations on Primitive Types.
CS2100 Computer Organisation
Data Representation COE 308 Computer Architecture
Bits, Data Types, and Operations
Chapter 2 Bits, Data Types, and Operations
Programming and Data Structure
NUMBER SYSTEMS.
Data Representation ICS 233
Lec 3: Data Representation
Data Representation.
Lecture No. 4 Number Systems
Number Representation
Number Systems and Binary Arithmetic
DATA REPRESENTATION Data Types Complements Fixed Point Representations
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
CHAPTER 1 : INTRODUCTION
COMPUTING FUNDAMENTALS
CS1010 Programming Methodology
Chapter 1 Number Systems, Number Representations, and Codes
Javascript, Loops, and Encryption
Chapter 2 Bits, Data Types, and Operations
Data Representation COE 301 Computer Organization
Data Representation Data Types Complements Fixed Point Representation
MMNSS COLLEGE,KOTTIYAM DEPARTMENT OF PHYSICS
Chapter 2 Bits, Data Types, and Operations
ASCII Character Codes nul soh stx etx eot 1 lf vt ff cr so
Numbering System TODAY AND TOMORROW 11th Edition
ECEG-3202 Computer Architecture and Organization
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Cosc 2P12 Week 2.
Number Systems Lecture 2.
Data Representation ICS 233
Introduction to Computer Engineering
DATA REPRESENTATION Data Types Complements Fixed Point Representations
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Cosc 2P12 Week 2.
Data Representation COE 308 Computer Architecture
Chapter 2 Bits, Data Types, and Operations
Presentation transcript:

Chapter 2 Data Types and Representations Decimal, Binary, Octal, and Hexadecimal Number System Complement Number System Fixed Point and Floating Point Numbers Character Codes, Cube Representation Chapter 2 Decimal, Binary, Octal, and Hexadecimal Number System Complement Number System Fixed Point and Floating Point Numbers Character Codes, Cube Representation

Positional Number System Each number is represented by a string of digits, in which the position of each digit has an associated weight 1234.56 = 1 ∙ 1000 + 2 ∙ 100 + 3 ∙ 10 + 4 ∙ 1 + 5 ∙ 0.1 + 6 ∙ 0.01 In general, any decimal number D of the form has the value dm – 1 dm – 2 …d1 d0 .d–1 d–2 …d–n Least significant digit Radix point Most significant digit Positional Numbers D = dm – 1 ∙ 10m – 1 + …+ d0 ∙ 100 + d–1 ∙ 10–1 + …+ d–n ∙ 10–n = Radix

Binary Number System General form of a binary number: Its value is equivalent to Examples bm – 1 bm – 2 …b1 b0 b–1 b–2 …b–n Least significant bit (LSB) Binary point Most significant bit (MSB) B = Radix 2 Binary Number System 101012 = 1 ∙ 16 + 0 ∙ 8 + 1 ∙ 4 + 0 ∙ 2 + 1 ∙ 1 = 2110 1101012 = 1 ∙ 32 + 1 ∙ 16 + 0 ∙ 8 + 1 ∙ 4 + 0 ∙ 2 + 1 ∙ 1 = 5310 10.1012 = 1 ∙ 2 + 0 ∙ 1 + 1 ∙ 0.5 + 0 ∙ 0.25 + 1 ∙ 0.125 = 2.62510 0.11112 = 1 ∙ 0.5 + 1 ∙ 0.25 + 1 ∙ 0.125 + 1 ∙ 0.0625 = 0.937510

Octal and Hexadecimal Numbers Binary Octal Decimal Hexadecimal 1 10 2 11 3 100 4 101 5 110 6 111 7 1000 8 1001 9 1010 12 A 1011 13 B 1100 14 C 1101 15 D 1110 16 E 1111 17 F 10000 20 10001 21 Numbers Radix Binary 2 Octal 8 Decimal 10 Hexadecimal 16 Octal and Hexadecimal Numbers Different representation of numbers 0 through 17 Back to Conversion of Numbers (Part II)

Conversion of Numbers (Binary, Octal, Hexadecimal) Binary to Octal Conversion Start at the binary point and work left. Separate the bits into groups of three, replace each group with corresponding octal digit. Binary to Hexadecimal Conversion Start at the binary point and work left. Separate the bits into groups of four, replace each group with corresponding hexadecimal digit. 10100111002 = 001 010 011 100 = 12348 Conversion of Numbers (Part I) 10100111002 = 0010 1001 1100 = 29C16

Conversion of Numbers (Binary, Octal, Hexadecimal) Conversion of Fractions Start at the binary point. Group the binary digits on the right into groups of three (Octal) or four (Hexadecimal). Conversion to Binary Numbers Replace each octal or hexadecimal digit with corresponding 3-bit or 4-bit binary string from the Octal and Hexadecimal Table. 0.101112 = 0.101 110 = 0.568 = 0.1011 1000 = 0.B816 Conversion of Numbers (Part II) 7658 = 1111101012 765.4328 = 111110101.1000110102 FED16 = 1111111011012 FED.CBA16 = 111111101101.1100101110102

Conversion to Decimal Numbers S = S ∙ r + di i = m – 1 S = 0 Start i = 0 i = i – 1 Done D = = ((…((dm – 1)r + dm – 2)r + …)r + d1)r + d0 yes Conversion to Decimal Numbers no

Conversion from Decimal Numbers Divide S by r S = quotient di = remainder i = 0 S = D Start i = m – 1 i = i + 1 Done no yes D = = ((…((dm – 1)r + dm – 2)r + …)r + d1)r + d0 Dividing the top equation by r, we obtain the quotient Q and remainder R Q = (…((dm – 1)r + dm – 2)r + …)r + d1 R = d0 Conversion from Decimal Numbers

Conversion of Decimal Numbers Examples Problem: Convert (a) 179 to binary, (b) 467 to octal, and (c) 3417 to hexadecimal. Solution: (b) 4 6 7 ÷ 8 = 5 remainder 3 (LSD) remainder 2 remainder 7 (MSD) Therefore, 46710 7238 (a) 1 7 9 ÷ 2 = 8 remainder 1 (LSD) 4 remainder 1 remainder 0 5 remainder 1 (MSD) Therefore, 17910 101100112 (c) 3 4 1 7 ÷ 16 = 5 8 remainder 9 (LSD) 2 remainder 5 remainder 13 (MSD) Therefore, 341710 D5916 Examples: Convert (a) 179 to binary, (b) 467 to octal, and (c) 3417 to hexadecimal.

Addition of Binary Numbers xi yi ci ci+1 si 1 ci+1, si = xi + yi + ci c0 = 0 i = 0 Start i = m i = i + 1 Done no yes x 9 8 7 y 1 2 3 Carries x + y Decimal Addition Addition of Binary Digits 512 256 128 64 32 16 8 4 2 1 x (987) y (123) Carries x + y (1110) s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 Addition of Binary Numbers Binary Addition

Subtraction of Binary Numbers xi yi bi bi+1 di 1 bi+1, di = xi – yi – bi b0 = 0 i = 0 Start i = m i = i + 1 Done no yes x 9 8 7 y 1 2 3 Borrows x – y 6 4 Decimal Subtraction Subtraction of Binary Digits 512 256 128 64 32 16 8 4 2 1 x (987) y (123) Borrows x – y (864) d9 d8 d7 d6 d5 d4 d3 d2 d1 d0 Subtraction of Binary Numbers Binary Subtraction Back to Two’s-complement Subtraction

Sign Magnitude Representation Start addition subtraction s2 = s′2 s1 = s2 mr = m1 + m2 sr = s1 m1 > m2 m1 = m2 mr = m1 – m2 mr = 0 sr = 0 mr = m2 – m1 sr = s2 Done yes no A sign magnitude number <s, m>, consists of two parts: Sign and Magnitude The sign is either + or – The magnitude is an integer between 0 and the largest representable value Examples: Sign Magnitude Representation 011110112 = +12310 111110112 = –12310 D1 = < s1, m1 > and D2 = < s2, m2 > yields the result Dr = < sr, mr >

Complement Number System Radix-complement of a number D = is equal to: If digit complement d′ = (r – 1) – d then Therefore, is a negative number of D , since (rm – 1) – D = ( (r – 1) (r – 1) … (r – 1) – (dm – 1 dm – 2 … d0 ) ) = ( (r – 1) – dm – 1) ( (r – 1) – dm – 2 ) … ( (r – 1) – d0 ) = d′m – 1 d′m – 2 … d′0 = = D′ Complement Number System (Part I)

Complement Number System Decimal Two’s Complement Sign- Magnitude -8 1000 - -7 1001 1111 -6 1010 1110 -5 1011 1101 -4 1100 -3 -2 -1 0000 1000 or 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 Digit Binary Octal Decimal Hexa-decimal 1 7 9 F 6 8 E 2 - 5 D 3 4 C B A Complement Number System (Part II) Digit Complements Two’s Complement and Sign-Magnitude Representations

Two’s-complement Addition Adding two positive numbers generates a correct result Adding two negative numbers generates a correct result if carry is ignored 1 (+2) + (+4) (+6) Two’s-complement Addition (Part I) 1 (–2) + (–4) Ignored carry = 1 (–6)

Two’s-complement Addition Adding a positive and a negative number generates a correct result Adding large numbers may generate an incorrect result because of an overflow 1 (+2) + (–4) (–2) 1 (+4) + (+5) (–7) 1 (–4) + (–5) Ignored carry = 1 (+7) Two’s-complement Addition (Part II) Overflow rule: an overflow occurs when the sign of the sum is different than the signs of both operands

Two’s-complement Subtraction Direct subtraction using subtraction standard procedure Subtraction using two’s complement Start addition subtraction B2 = B2‘ + 1 Br = B1 + B2 Done (+2) 1 Two’s complement of (+4) + Carries (–2) (+2) 1 (+4) – Borrows (–2) ignore borrow =1 (–4) 1 Two’s complement of (–8) + Carries (+4) ignore carry =1 Two’s-complement Subtraction

Binary Multiplication Decimal Multiplication Binary Multiplication 1 4 multiplicand × 3 multiplier 2 3 × multiplicand 1 × multiplicand 8 product 1 multiplicand (14) × multiplier (13) product (182) Binary Multiplication

Shift-and-add Multiplication MR = multiplier bm–1 …b1 b0 (m-bit) MD = multiplicand (n-bit) PP = partial product Start Example of shift-and-add multiplication PP = 0 i = 0 1 multiplicand (14) × multiplier (13) initial partial product shifted multiplicand second partial product shifted zeros third partial product fourth partial product product (182) bi = 1 no yes PP = PP + (2i × MD) i = i + 1 Shift-and-add Multiplication i = m no yes Product = PP Done

Two’s-complement Multiplication Use multiplication procedure for unsigned numbers Negate multiplicand if multiplier sign is negative 1 multiplicand (–14) × multiplier (–13) extended partial product extended multiplicand extended shifted multiplicand all zeros extended, shifted, and negated multiplicand ignore carry product (182) Note: Carry out of MSB in the third PP is ignored before sign extension Carry out of MSB is ignored in the final product Sign truncation is needed in the final product Two’s-complement Multiplication

Binary Division Decimal Division Binary Division 1 3 quotient 14 ) 8 6 dividend 4 shifted (divisor x 1) reduced dividend 2 shifted (divisor x 3) remainder 1 quotient (13) 1110 ) dividend (186) shifted divisor reduced dividend remainder (4) Binary Division

Floating-point Numbers Floating-point numbers have the form mantissa × (radix) exponent Since radix is implicit, only mantissa and exponent must be represented explicitly Floating-point numbers are fixed-point numbers given by the mantissa, whose radix point is specified by the exponent Exponent is represented in the excess-code format called characteristic, obtained by adding a bias to the exponent: bias = radixs – 1 where s is equal to the number of bits in the exponent field 0 1 9 31 Floating-point Numbers Mantissa sign Signed exponent magnitude Sign Excess-127 characteristic Normalized Fraction General format 32-bit standard Implied binary point 0 1 12 63 Sign Excess-1032 characteristic Normalized Fraction 64-bit standard Implied binary point

Fixed-point vs. Floating-point The range is the interval of numbers from the largest to the smallest representable number The precision is the amount of numbers in a number interval 4-digit fixed number 4-digit floating-point number Integer Mantissa Exponent Representable numbers 0 – 9999 0 – 99 × 10 Range ~ 104 ~ 10101 Precision ~ 100× ~ 1× Example 1001 numbers between 1000 and 2000 11 numbers between 1000 and 2000 Fixed-point vs. Floating-point

Binary Codes for Decimal Numbers Binary-coded Decimals (BCD) 2421 Code Excess-3 Code Biquinary Code Decimal digit BCD (8421) 2421 Excess-3 Biquinary 0000 0011 0100001 1 0001 0100 0100010 2 0010 0101 0100100 3 0110 0101000 4 0111 0110000 5 1011 1000 1000001 6 1100 1001 1000010 7 1101 1010 1000100 8 1110 1001000 9 1111 1010000 Binary Codes for Decimal Numbers

American Standard Code for Information Interchange (ASCII) Character Codes b3b2b1b0 b6b5b4 000 001 010 011 100 101 110 111 0000 NUL DLE SP @ P ‘ p 0001 SOH DC1 ! 1 A Q a q 0010 STX DC2 “ 2 B R b r 0011 ETX DC3 # 3 C S c s 0100 EOT DC4 $ 4 D T d t 0101 ENQ NAK % 5 E U e u 0110 ACK SYN & 6 F V f v 0111 BEL ETB ’ 7 G W g w 1000 BS CAN ( 8 H X h x 1001 HT EM ) 9 I Y i y 1010 LF SUB * : J Z j z 1011 VT ESC + ; K [ k { 1100 FF FS , < L \ l | 1101 CR GS - = M ] m } 1110 SO RS . > N ^ n ~ 1111 SI US / ? O _ o DEL NUL Null SOH Start of heading STX Start of text ETX End of text EOT End of transmission ENQ Enquiry ACK Acknowledge BEL Bell BS Backspace HT Horizontal tab LF Line feed VT Vertical tab FF Form feed CR Carriage return SO Shift out SI Shift in SP Space DLE Data link escape DC1 Device control 1 DC2 Device control 2 DC3 Device control 3 DC4 Device control 4 NAK Negative acknowledgement SYN Synchronize ETB End transmission block CAN Cancel EM End of medium SUB Substitute ESC Escape FS File separator GS Group separator RS Record separator US Unit separator DEL Delete or rubout Character Codes American Standard Code for Information Interchange (ASCII)

Cube Representation 0 1 (a) 101 111 001 011 000 010 100 110 10 11 00 01 Any n-bit string can be represented by an n-cube with 2n vertices, each corresponding to a particular string of n bits Any m-subcube has the same n – m bits and m bits that take all 2n possible combinations of 0s and 1s Distance between two vertices is equal to 1 + the number of vertices on the shortest path between two vertices (c) (b) 1110 1111 1010 0111 1100 1101 1000 1001 (d) Cube Representation 0110 0111 0010 0011 0100 0101 0000 0001 n-cubes for n = 1, 2, 3, and 4