300 likes | 470 Views
DIGITAL SYSTEMS. Number systems & Arithmetic Rudolf Tracht and A.J. Han Vinck. Number Systems. A set of symbols representing digits, S A string of symbols represents a value Value may be computed from the position of digits in a string (positional number system)
E N D
DIGITAL SYSTEMS Number systems & Arithmetic Rudolf Tracht and A.J. Han Vinck
Number Systems • A set of symbols representing digits, S • A string of symbols represents a value • Value may be computed from the position of digits in a string (positional number system) • Example: Decimal number system • base 10 or radix 10 • (724.6)10=7x100 + 2x10 + 4x1 + 6x1/10
examples • Decimal: r = 10, S = {0, 1, 2, ..., 9} • Binary: r = 2, S = {0,1} • Octal:r = 8, S = {0,1,2,3,4,5,6,7} • Hexadec: r = 16, S = {0, ..., 9, A,B,C,D,E,F} • Conversion from one base to another: -By successive division or multiplications by the radix.
Positional number system • Base r • A number is a string • Significance of a digit in a string is indicated by its position
Example for binary numbers • A binary number is a weighted number. The structure is 2n-1 23 22 21 20. 2-1 2-2 2-3 2-n where n is the number of bits from the binary point. • Ex: conversion of the binary number 1 1 0 1 0 . 0 1 1 • Weight 24 23 22 21 20 . 2-1 2-2 2-3 • Binary 1 1 0 1 0 . 0 1 1 1 1 0 1 0 . 0 1 1 = 24 +23 +21 +2-2 +2-3 = 16 + 8 + 2 + 0.25 + 0.125 = 26.375
2-to-10 and 10-to-2 Converting a binary number to a decimal number is easy: there is a radix point here What about the way back?
Addition and subtraction of binary numbers • Same as in school: borrow from preceding neighbor By example: 1 1 1 1 0 0 1 1 1 1 1 0 0 190 1 0 1 1 1 1 1 0 229 1 1 1 0 0 1 0 1 141 1 0 0 0 1 1 0 1 -46 0 0 1 0 1 1 1 0 331 1 0 1 0 0 1 0 1 1 183 1 0 1 1 0 1 1 1
Multiplication/division • Examples • Multiplication: 7 x 5 = 35 111 x 101 = 111 + 000 + 11100 = 100011 = 35 • Division: 12 / 4 = 3 1100 / 100 = 11
Negative numbers • Signed magnitude form • 1- complement • 2-complement
Signed magnitude representation • The most significant bit indicates the sign • 01010101 = +85 • 11010101 = - 85 • Problem is the adding/subtracting of numbers
1-complement representation • Binary complement for negative numbers 17 = 00010001 11101110 = -17 119 = 01110111 10001000 = -119 sign
2-complement representation • Positive numbers +A • Negative numbers -A where
4-bit numbers 0 0 000 -8 1 000 1 0 001 -1 1 111 2 0 010 -2 1 110 3 0 011 -3 1 101 4 0 100 -4 1 100 5 0 101 -5 1 011 6 0 110 -6 1 010 7 0 111 -7 1 001
remarks • Adding/subtracting • ignoring any carries beyond the MSB • MSB = most significant bit (largest weight) • correct as long as range not exceeded +3 0011 +4 0100 +4 0100 -7 1001 +7 0111 -3 1101
implementation • Note: we represent a negative number –A as Example: 99 = 01100011 -99 = 10011100 + 1 = 10011101 Example: 98 = 01100010 -98 = 10011101 + 1 = 10011110
Overflow detection • MSB different No problem • Reason: always within range Example: -3 1101 +3 0011 +6 0110 -6 1010 +3 0011 -3 1101 • MSB the same MSB addition different Example: -3 1101 +5 0101 -6 1010 +6 0110 -9 0111 = +7 +11 1011 =-5
In other words • Calculations are done modulo 2r+1 • Let a and b be positive numbers; 0 a,b < 2r ; - a = 2r+1 – a mod 2r+1 + a + b = c < 2r no problem ( overflow detected by sign comparison) - a - b = 2r+1 – a + 2r+1 – b = 2r+1 – (a + b) + 2r+1 = 2r+1 – (a + b) modulo 2r+1 no problem if (a + b) < 2r ( otherwise overflow detected ) - a + b = 2r+1 – a + b = b –a modulo 2r+1 for b a = 2r+1 – (a - b ) for b a
Floating point numbers • Decimal • Example: + 0.234567 x 109 sign mantissaexponent
Binary floating point (IEEE standard) • Binary: • single- (32 bits), double- (64 bits), extended precision (80 bits) S E = exponent F = mantissa 1 8 bits 23 bits To find E and F, write a binary number as 1. a1 a2 a3 a4 … 2x • F =a1 a2 a3 a4 … • E = 127 + x range of x: -126 ≤ x ≤ 128 The number 0.0 is represented by all 0’s Infinity is represented by all 1’s in the exponent and 0’s in the mantissa Number = (-1)S(1+F)(2E-127)
Hexadecimal numbers • Widely used in computer and microprocessor applications • Base is 16: Decimal binary hexadecimal • 0 0000 0 • 1 0001 1 • 2 0010 2 • 3 0011 3 • 4 0100 4 • 5 0101 5 • 6 0110 6 • 7 0111 7 • 8 1000 8 • 9 1001 9 • 10 1010 A • 11 1011 B • 12 1100 C • 13 1101 D • 14 1110 E • 15 1111 F
Hexadecimal numbers (count) 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 etc. • i.e. In decimal 1316 means 1 x 16 + 3 2C16 means 2 x 16 + 12 A2B16 means 10 x 162 + 2 x 161 + 11 • With 2 hexadecimal digits we can count up to FF16 = 255 decimal • Each hexadecimal character represents a 4-bit number!
Hexadecimal numbers (examples) • Example Binary to hexadecimal 1100 1010 0101 0111 00111111 0001 0110 1001 C A 5 7 3 F 1 6 9 • Example Hexadecimal to binary 6BD3 = 6 x 163 + 11 x 162 + 13 x 161 + 3 in binary: 0110 1011 1101 0011
octal numbers • used in computer and microprocessor applications • Base is 8: 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 • 8 1000 10 • 9 1001 11 • 10 1010 12 • 11 1011 13 • 12 1100 14 • 13 1101 15 • 14 1110 16 • 15 1111 17
octal numbers (count) 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 30 etc. • i.e. In decimal 138 means 1 x 8 + 3 218 means 2 x 8 + 1 3278 means 3 x 82 + 2 x 81 + 7 • With 2 octal digits we can count up to 778 = 63 decimal • Each octal character represents a 4-bit number!
octal numbers (examples) • Example Binary to octal 100 010 101 111 011 111 001 110 001 4 2 5 7 3 7 1 6 1 • Example octal to binary 6233 = 6 x 83 + 2 x 82 + 3 x 81 + 3 in binary: 110 010 011 011
octal numbers (examples) • Conversion digital to octal • Example: 359 decimal = 5 x 82 (320) + 4 x 8 (32) + 7
Binary Coded Decimal • Conversion table Decimal BCD 0 0000 1 0001 2 0010 decimal 35 = 0011 0101 BCD 3 0011 decimal 98 = 1001 1000 BCD 4 0100 5 0101 1000 0110 BCD = 86 decimal 6 0110 7 0111 8 1000 9 1001
Some other codes Decimal BCD 1-out-of-10 Biquinary Binary coded decimal 0 0000 1000000000 0100001 1 0001 0100000000 0100010 2 0010 0010000000 0100100 3 0011 0001000000 0101000 4 0100 0000100000 0110000 5 0101 0000010000 1000001 6 0110 0000001000 1000010 7 0111 0000000100 1000100 8 1000 0000000010 1001000 9 1001 0000000001 1010000 Application: error detection (check!)
Gray Code • By example for binary words of length 3 # codeword 0 000 numbers differ by 1 binary difference 1 1 001 2 011 3 010 Homework: design a general code for length n 4 110 5 111 6 101 7 100
parity • An extra bit is added to a string to make the number of 1’s always even (or odd if desired) • i.e. the parity for 011 is 0 01 1 0 the parity for 111 is 1 1 1 1 1 RESULT: any odd number of changes detectable!