Unit Numbering Systems Fundamentals of Logic Design EE2369 Prof. Eric MacDonald Fall Semester 2003 Digital Systems Overview Digital Systems are Home PC XBOX or Playstation2 Cell phone Network router Data processing Communications Control Air Conditioning control in the home Transmission controller under the hood Elevator controller Why Digital Systems? Accurate depending on number of digits used CD Music is digital Vinyl Records were analog DVD Video and Audio mp3 (quality depends on sampling/amount of bits) Reliable Error Correction Capabilities Discrete Values with Large Noise Margin Technology can be implemented as fast, cheap CMOS semiconductors Levels of Design Abstraction High Level System Design (senior class) Design the box and decide how components are connected Middle Level Logic Design (this class!) Design the chips inside the box Low Level Circuit Design (senior class) Design the macros used in the chip by logic designers Design with transistors and implement physically Numbering systems Dissecting Decimal Numbers Western World Decimal or base 0 The system that we all know and take for granted 0 probably picked because of the number of fingers on human hands Egyptians used base 0 but only accumulatively Romans used base 0 and had some positional notation Mayans Vigesimal or base 20 had concept of zero and had a modern positional notation Allowed for representing a large range (very small to very large numbers) positional notation allows for long arithmetic Not sure why they picked 20? Doesn t matter really. Computers and Digital Systems Binary or base 2 easy to implement physically high or low voltage on wire allows for use of Boolean math and philosopher s logic true or false = high or low = one or zero = on or off 0 2 4. 2 5 0 000 s 00 s 0 s s. /0 s /00 s 0 3 0 2 0 0 0. 0-0 -2 Note: All digits confined to one of 0 characters (0,, 2, 3, 4, 5, 6, 7, 8, 9)
Positional Notation Dissecting Binary Numbers 0 2 4. 2 5 0 a m a 2 a a 0 a - a l 0 0. 2 = 2.75 0 8 s 4 s 2 s s. /2 s /4 s 0 m 0 2 0 0 0. 0-0 -l Base is 0 so R = 0 (R could be any positive integer) N = a m * R m + a 2 * R 2 + a * R + a 0 * R 0 + a - * R - + a -l * R -l 2 3 2 2 2 2 0. 2-2 -2 Note: All digits confined to one of 2 characters (0 or ) Computers love this Converting Binary to Decimal (ex) Converting Binary to Decimal (ex2) 0 2 = 0 0 0. 2 = 2.75 0 8 s 4 s 2 s s 8 + 0 + 2 + = 0 8 s 4 s 2 s s. /2 s /4 s 8 + 4 + 0 + 0 + ½ + ¼ = 2.75 Converting Binary to Decimal (ex3) Dissecting Hexadecimal Numbers 0 0 0. 0 2 = 8.25 0 8 s 4 s 2 s s. /2 s /4 s 8 + 0 + 0 + 0 + 0 + ¼ = 8.25 3 E 6 256 s 6 s s 6 2 6 6 0 = 38 0 A = 0 B = C = 2 D = 3 E = 4 F = 5 Note: All digits confined to one of 6 characters (0 to 9 and A to F) 2
Why Hexadecimal? Binary to Hexadecimal Easy! One Hexadecimal digit represents four binary digits Hexadecimal is more human readable Can quickly convert large binary numbers to hexadecimal and back by inspection Decimal 0 2 3 4 5 6 7 8 Hexadecimal 0 2 3 4 5 6 7 8 Binary 0000 000 000 00 000 00 00 0 000 00 00 B C 5 9 9 00 0 a 00 2 3 b c d 0 0 BC5 much easier to read than 0000 4 e 0 5 f Long Hand Conversion Long Hand Conversion 2 78 2 39 2 9 2 9 2 4 2 2 2 0 From Decimal Integer to any other Base Convert 78 0 to binary remainder 0 - a0 - s least significant digit first remainder - a 2 s remainder - a2 4 s remainder - a3 8 s remainder 0 - a4 6 s remainder 0 - a5 32 s Answer: 000 remainder - a6 64 s most significant digit last 0.75 x 2 ().50 => a - 0.50 x 2 ().00 => a -2 0.00 x 2 (0).00 => a -3 finished when answer is 0.00 From Decimal Fraction to any other Base 0.75 decimal to binary Answer: 0.0 Long Hand Conversion Long Hand Binary Addition General Guidelines To convert to decimal, use positional notation equation To convert to/from arbitrary bases (say base n to m) first convert n to decimal second convert from decimal to m To convert numbers with integers and fractions treat them separately with the previous long hand conversions concatenate the results Hexadecimal to/from binary can be done by inspection Octal (base 8) to/from binary can also be done by inspection Addition Table 0 + 0 = 0, c=0 0 + =, c=0 + 0 =, c=0 + = 0, c= But Carry One to next column + 2 0 = 6 0 = +00 0 00 = 8 0 3
Long Hand Binary Subtraction Long Hand Binary Multiplication Subtraction Table 0-0 = 0 0 - = - 0 = - = 0 - But borrow One from next column 2 0 = 6 0 = - 00 00 = 6 0 Multiplication Table 0 * 0 = 0 0 * = 0 * 0 = 0 * = * 2 0 = 6 0 = + * 00 0000 0000 00000 =72 0 Long Hand Binary Division Long Hand Binary Division 24 divided by 6 00 = 4 0 0 0 0 000 0 = 0 000-00 - 000-000 = 0 remainder 78 divided by 7 Representing Negative Numbers Sign and Magnitude system Sign and Magnitude system intuitive human readable good for multiplication, bad for addition/subtraction One s complement less intuitive used by Cray computers Two s complement even less intuitive (at first) good for addition / subtraction used almost exclusively in industry sign bit = - 0 = + 000 2 = -6 0 magnitude (same in this case) 4
One s complement Two s complement 2 = -6 0 formal conversion => N = (2 n ) N Example (2 n -) N = 6-000 simple conversion => flip all bits 00 2 = -6 0 formal conversion => N* = N + Example (2n-) N = 6-000 add + 0000 00 Two s complement simple convert Find first from the right 00000 2 = 6 0 invert each digit to the left 0000 2 = 6 0 000 2 = 6 0 00 2 = 6 0 until you reach the left end Two s Complement Addition Addition is identical to unsigned binary addition except for possibility of overflow and need for ignoring sign carry bit Formal subtraction operation unnecessary negate one number to negative two s complement add the numbers (same as subtraction) Overflow adding two positive numbers or negative numbers can result in overflow check for sign change to detect overflow the sum of two positive numbers should be positive the sum of two negative numbers should be negative Binary Codes BCD clock example Binary Coded Decimal (8-4-2- weighted code) used with simple LED displays (watch display, etc) 6-3-- Weighted code Excess-3 code 2-out-of-5 code Gray code ASCII 2 : 4 5 000 000 : 000 00 values 00 through not legal values 5
Other codes 4b/5b code 00 MBit Ethernet 6-3-- code distributed more evenly less absolute error for a single bit corrupted Excess-3 code distributed more evenly more likely to have a one in the 4 th position 2-out-of-5 code error checking convenient if one or three bits high, you have an error. Gray Code interesting in cases where next symbol is a single increment or decrement away results in less switching hazards when feeding combinatorial logic less power / longer battery life only switch one line at time Good for finite state machine state assignments (later chapter) 4 bits translated to 5 bits (6 symbols out of 32) Extra symbols for start, stop and idle Error correction for single bit corruption Error detection for two more corrupted bits 00 MBit Ethernet actually runs at 25 MBits 6