Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Data Types and Representations

Similar presentations


Presentation on theme: "Chapter 2 Data Types and Representations"— Presentation transcript:

1 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

2 Positional Number System
Each number is represented by a string of digits, in which the position of each digit has an associated weight = 1 ∙ ∙ ∙ ∙ ∙ ∙ 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 ∙ d–1 ∙ 10–1 + …+ d–n ∙ 10–n = Radix

3 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 = 1 ∙ ∙ ∙ ∙ ∙ 1 = 2110 = 1 ∙ ∙ ∙ ∙ ∙ ∙ 1 = 5310 = 1 ∙ ∙ ∙ ∙ ∙ = = 1 ∙ ∙ ∙ ∙ =

4 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)

5 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. = = 12348 Conversion of Numbers (Part I) = = 29C16

6 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.568 = = 0.B816 Conversion of Numbers (Part II) 7658 = = FED16 = FED.CBA16 =

7 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

8 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

9 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 (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.

10 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

11 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

12 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 = = –12310 D1 = < s1, m1 > and D2 = < s2, m2 > yields the result Dr = < sr, mr >

13 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)

14 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

15 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)

16 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

17 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

18 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

19 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

20 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

21 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

22 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 Floating-point Numbers Mantissa sign Signed exponent magnitude Sign Excess-127 characteristic Normalized Fraction General format 32-bit standard Implied binary point Sign Excess-1032 characteristic Normalized Fraction 64-bit standard Implied binary point

23 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

24 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 1 0001 0100 2 0010 0101 3 0110 4 0111 5 1011 1000 6 1100 1001 7 1101 1010 8 1110 9 1111 Binary Codes for Decimal Numbers

25 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)

26 Cube Representation 0 1 (a) 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) (d) Cube Representation n-cubes for n = 1, 2, 3, and 4


Download ppt "Chapter 2 Data Types and Representations"

Similar presentations


Ads by Google