Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Lecture 3 ENGRE 254 1/14/09 1 Lecture 1 review Digital signals assume two values represented by “0” and “1”. Typically a “0” represents a voltage near 0 volts, and a “1” represents a voltage near 5 volts (3.3 volts for newer devices). Two types of digital circuits: • Combinational -Simpler -Output a function of present input. -Consists of logic gates without feedback. • Sequential -The output is a function of not only the present input, and current state which is determined by past events. - Consists of flip-flops or gates with feedback. 2 3 Non-decimal arithmetic. • Same rules as decimal. • Different addition, subtraction, multiplication tables. • Binary Examples 1 1 0 1 1 1 0 1 0 1 0 1 1 0 0 1 0 0 1 10 0 10 1 0 0 1 0 0 1 0 1 1 0 1 1 4 Binary multiplication and division example 1 0 0 0 1 1 0 1 0 0 1 0 1 1 1 0 1 1 1 1 11 101 1111 101 101 101 0 5 Base 5 multiplication example X 0 1 2 3 4 0 0 0 0 0 0 1 0 1 2 3 4 2 0 2 4 11 13 3 0 3 11 14 22 4 0 4 13 22 31 3 4 1 4 6 Representing negative numbers • Sign-magnitude. +199.1210, -199.1210, -1012 – This is what people normally use. – Complicates digital logic. • Complement number systems. – May use radix or radix-1 (actually rn or rn – 1 for n digit words). – In base 10 we use 10’s complement or 9’s complement. – In base 2 we use 2’s complement or 1’s complement. – Simplifies digital logic. Eliminates need for separate hardware for addition and subtraction. – The 2’s complement has become the standard. – We will concentrate on 2’s complement. 7 9’s and 10’s complement. 184910 10 10000 1849 8151 1849 9999 1849 8150 9 10 8 9 One’s Complement 1710 000100012 , 1210 000011002 00010001 111111112 000100012 1 2 111011102 00001100 111111112 000011002 1 2 111100112 Rule: Complement each bit. 10 Two’s complement • To find 2’s complement. 2 000100012 10000000 00010001 111011112 or better 00010001 00010001 1 111011112 • Easy way. Starting at rightmost bit, copy through first 1 then complement each bit. 2 2 1 2 00010001 ?, 2 2 00001100 ? 2 2 11 2’s complement • With n bits we can represent binary values form 0 to 2n-1. – For example with 3 bits: 000, 001, …, 111. – With 3 bits 111 + 001 = 000. (Overflow!) • For an n bit number B, B2 = 2n – B • -B = -2n + B2 • A – B = -2n + A + B2 Rule: To subtract A – B take two’s complement of B and add. Ignore contents of 2n bit position. 12 Examples 17 000100012 12 000011002 17 12 29 000111012 17 12 5 000001012 17 12 5 000001012 11111011 2 2 17 12 29 11100011 2 2 13 Two’s complement example (using 6 bits) 1710 1210 510 0100012 0011002 0 001012 0100012 2 11010 02 1 0001012 Consider other examples such as: 12-17, -12-(-17), -17-(-12), etc. 14 Binary codes for decimal numbers. • Decimal numbers are represented in a digital system using a string of bits. – This can be done in various ways. • A set of n-bit strings where different strings represent different numbers or other things is called a code. • A particular combination of n-bit values is called a code word. • See Table 2-9 on page 49 for example codes for decimal digits. • A common and convenient code for decimal numbers is BCD. 15 16 Lab 2: Wire up the circuit below and verify that it converts 2421 code to BCD. For example an input of “1111” produces output of “1001”. 1 1 1 0 1 1 0 1 1 17 BCD • BCD is a binary representation of decimal numbers in a form that can easily be interpreted by a person. • Suppose we want to store 149210 in a 16 bit computer word. – In binary 149210 = 0000 0101 1101 01002 – In BCD 149210 is stored as – 0001 0100 1001 0010BCD 18 BCD addition • Suppose 1492 and 1066 are stored in BCD. 1492 0001 0100 1001 0010 1066 0001 0000 0110 0110 If we add these in binary we get an incorrect result. Rule to add BCD numbers start at least significant BCD position (4 bits) add in binary if there is a carry or the result is grater than 9 add 6. Repeat for each BCD position. 19 BCD addition example 0001 0100 1001 0010 0001 0000 0110 0110 ____ 1000 = 8 < 9 no carry OK 1111 = 15 > 9 must add 6 0110 ___1 0101 Now OK (9 + 6 = 15) ____ 0101 = 5 < 9 no carry OK 0010 = 2 < 9 no carry OK Final BCD Answer = 0010 0101 0101 1000 149210 + 106610 = 255810 Conclusion BCD addition is easy we just have to know when to correct by adding 6. Some microprocessors have a decimal adjust addition (DAA) instruction for automatically performing BCD addition correction. 20 Gray Code The most common example of a unit distance code (Successive values differ by only one bit). See Table 2-10 page 52. Binary code Gray code 21 Decimal Binary Gray 0 000 000 1 001 001 2 010 011 3 011 010 4 100 110 5 101 111 6 110 101 7 111 100 22 Gray Code conversion Binary to Gray • The binary value B = bn…b2 b1 b0 can be converted to Gray code G = gn…g2 g1 g0. • With gi = bi+1 bi or G = B B/2 Examples: If B =110 then G = 110 011 = 101 If B = 10110111then G = 10110111 1011011 = 11101100 23 Gray to Binary From gi = bi bi+1 it follows that bi = gi bi+1 • • • • • • • • • • Example: Let G = 01011111. Then using b8 = 0. b7 = g7 b8 = 0 0 = 0 b6 = g6 b7 = 1 0 = 1 b5 = g5 b6 = 0 1 = 1 b4 = g4 b5 = 1 1 = 0 b3 = g3 b4 = 1 0 = 1 b2 = g2 b3 = 1 1 = 0 b1 = g1 b2 = 1 0 = 1 b0 = g0 b1 = 1 1 = 0 B = 01101010 24 Character Codes • ASCII most common code for representing alphanumeric characters. – 7 bit code. Typically stored in a byte. The 8th bit can be used for parity or extended characters. – See Table 2-11 on page 54. • Microsoft has introduced Unicode, a 16-bit code, and MBCC to provided windows support for extended characters (Japanese etc.). 25 26 n-cubes and distance • The values of an n-bit code can be considered as the coordinates of vertices of an n-dimensional Boolean hypercube. – See figure 2-8 on page 57. • Useful for visualizing coding concepts. – See figure 2-9 on page 57. • Hamming distances – The number of bits in which the coordinates of two points differ. – See figure 2-10 page 59. • m-subcube – a set of 2m vertices in which n-m bits of the coordinates have the same value. – See Figure 2-8 Page 57 27 28 29 30