1 / 33

Digital Logic Design Lecture 3 Complements , Number Codes and Registers

Digital Logic Design Lecture 3 Complements , Number Codes and Registers. Overview. C omplement of numbers Addition and subtraction Binary coded decimal Gray codes for binary numbers ASCII characters Moving towards hardware Storing data Processing data. Complements.

Download Presentation

Digital Logic Design Lecture 3 Complements , Number Codes and Registers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Digital Logic DesignLecture 3Complements,Number Codes and Registers

  2. Overview • Complement of numbers • Addition and subtraction • Binary coded decimal • Gray codes for binary numbers • ASCII characters • Moving towards hardware • Storing data • Processing data

  3. Complements • In general, we (human beings) express negative numbers by placing a minus (-) sign at the left end of the number. Similarly while representing the integers in binary format, we can leave the left-most bit be the sign bit. If the left-most bit is a zero, the integer is positive; if it is a one, it is negative. • Zero is positive and -0 = 0 • The top-most bit should tell us the sign of the integer. • The negative of a negative integer is the original integer ie., -(-55) is 55. • x - y should give the same result as x + (-y). That is, 8 - 3 should give us the same result as 8 + (-3). • Negative and positive numbers shouldn't be treated in different ways when we do multiplication and division with them.

  4. Complement • If we consider only positive numbers, this would allow for all numbers from 0 (naturally represented by 00000000) to and inclusively 255 (represented by 11111111) • The most obvious solution is to spare the first bit as a sign indicator, thus leaving the 7 last bits to represent the numbers. • This simple way to represent negative numbers has for it the equally simple way to compute the negative of a given number: just invert the first bit!. Hence, the number 3, for example, represented as (00000011) will give (10000011) for -3 (we have just toggled the first bit). • This simple way has a drawback: the negative of 0 (00000000) is now (10000000), known as -0

  5. 000011002 = 1210 111101002 = -1210 Sign bit Sign bit Magnitude Magnitude Two’s Complement Representation • The two’s complement of a binary number involves inverting all bits and adding 1. • 2’s comp of 00110011 is 11001101 • 2’s comp of 10101010 is 01010110 • For an n bit number N the 2’s complement is (2n-1) – N + 1. • Called radix complement by Mano since 2’s complement for base (radix 2). • To find negative of 2’s complement number take the 2’s complement.

  6. Two’s Complement Shortcuts • Algorithm 1 – Simply complement each bit and then add 1 to the result. • Finding the 2’s complement of (01100101)2 and of its 2’s complement… N = 01100101 [N] = 10011011 10011010 01100100 + 1 + 1 --------------- --------------- 10011011 01100101 • Algorithm 2 – Starting with the least significant bit, copy all of the bits up to and including the first 1 bit and then complementing the remaining bits. • N = 0 1 1 0 0 1 0 1 [N] = 1 0 0 1 1 0 1 1

  7. Finite Number Representation • Machines that use 2’s complement arithmetic can represent integers in the range -2n-1 <= N <= 2n-1-1 where n is the number of bits available for representing N. Note that 2n-1-1 = (011..11)2 and –2n-1 = (100..00)2 • For 2’s complement more negative numbers than positive. • For 1’s complement two representations for zero. • For an n bit number in base (radix) z there are zn different unsigned values. (0, 1, …zn-1)

  8. 0 1 1 0 0 + 0 0 0 0 1 -------------- 0 0 1 1 0 1 0 -------------- 0 1 1 0 1 Add carry Final Result 1’s Complement Addition • Using 1’s complement numbers, adding numbers is easy. • For example, suppose we wish to add +(1100)2 and +(0001)2. • Let’s compute (12)10 + (1)10. • (12)10 = +(1100)2 = 011002 in 1’s comp. • (1)10 = +(0001)2 = 000012 in 1’s comp. Add Step 1: Add binary numbers Step 2: Add carry to low-order bit

  9. 1’s Complement Subtraction • Using 1’s complement numbers, subtracting numbers is also easy. • For example, suppose we wish to subtract +(0001)2 from +(1100)2. • Let’s compute (12)10 - (1)10. • (12)10 = +(1100)2 = 011002 in 1’s comp. • (-1)10 = -(0001)2 = 111102 in 1’s comp. 0 1 1 0 0 - 0 0 0 0 1 -------------- 0 1 1 0 0 + 1 1 1 1 0 -------------- 1 0 1 0 1 0 1 -------------- 0 1 0 1 1 1’s comp Step 1: Take 1’s complement of 2nd operand Step 2: Add binary numbers Step 3: Add carry to low order bit Add Add carry Final Result

  10. 2’s Complement Addition • Using 2’s complement numbers, adding numbers is easy. • For example, suppose we wish to add +(1100)2 and +(0001)2. • Let’s compute (12)10 + (1)10. • (12)10 = +(1100)2 = 011002 in 2’s comp. • (1)10 = +(0001)2 = 000012 in 2’s comp. 0 1 1 0 0 + 0 0 0 0 1 -------------- 0 0 1 1 0 1 Add Step 1: Add binary numbers Step 2: Ignore carry bit Final Result Ignore

  11. 2’s Complement Subtraction • Using 2’s complement numbers, follow steps for subtraction • For example, suppose we wish to subtract +(0001)2 from +(1100)2. • Let’s compute (12)10 - (1)10. • (12)10 = +(1100)2 = 011002 in 2’s comp. • (-1)10 = -(0001)2 = 111112 in 2’s comp. 0 1 1 0 0 - 0 0 0 0 1 -------------- 0 1 1 0 0 + 1 1 1 1 1 -------------- 1 0 1 0 1 1 2’s comp Step 1: Take 2’s complement of 2nd operand Step 2: Add binary numbers Step 3: Ignore carry bit Add Final Result Ignore Carry

  12. 0 1 1 0 1 + 1 1 0 1 1 -------------- 1 0 1 0 0 0 carry 2’s Complement Subtraction: Example #2 • Let’s compute (13)10 – (5)10. • (13)10 = +(1101)2 = (01101)2 • (-5)10 = -(0101)2 = (11011)2 • Adding these two 5-bit codes… • Discarding the carry bit, the sign bit is seen to be zero, indicating a correct result. Indeed, (01000)2 = +(1000)2 = +(8)10.

  13. 2’s Complement Subtraction: Example #3 • Let’s compute (5)10 – (12)10. • (-12)10 = -(1100)2 = (10100)2 • (5)10 = +(0101)2 = (00101)2 • Adding these two 5-bit codes… • Here, there is no carry bit and the sign bit is 1. This indicates a negative result, which is what we expect. (11001)2 = -(7)10. 0 0 1 0 1 + 1 0 1 0 0 -------------- 1 1 0 0 1

  14. 0 1 1 0 1 + 1 1 0 1 1 -------------- 1 0 1 0 0 0 carry 2’s Complement Subtraction • Let’s compute (13)10 - (5)10. • (13)10 = +(1101)2 = (01101)2 • (-5)10 = -(0101)2 = (11011)2 • Adding these two 5-bit codes… • Discarding the carry bit, the sign bit is seen to be zero, indicating a correct result.

  15. Data Representation and Communication • Human communication • Includes language, images and sounds • Computers • Process and store all forms of data in binary format • Conversion to computer-usable representation using data formats • Define the different ways human data may be represented, stored and processed by a computer

  16. Data Representation and Communication • Numbers are important to computers as they • Represent information precisely • Can be processed • Decimal numbers are favored by humans. Binary numbers are natural to computers. Hence, conversion is required. • If little calculation is required, we can use some coding schemes to store decimal numbers, for data transmission purposes. • Examples: BCD (or 8421), Excess-3, 8-4-2-1, 2421, etc. • Each decimal digit is represented as a 4-bit code. • The number of digits in a code is also called the length of the code.

  17. BCD • Binary Coded Decimal (BCD) represents each decimal digit with four bits • Ex. 0011 0010 1001 = 32910 • This is NOT the same as 0011001010012 • Why do this? Because people think in decimal. Note: the following 6 bit patterns are not used: 1010 1011 1100 1101 1110 1111

  18. Putting It All Together • BCD not very efficient • Used in early computers (40s, 50s) • Used to encode numbers for seven-segment displays. • Easier to read?

  19. Gray Code • Gray code is not a number system. • It is an alternate way to represent four bit data • Only one bit changes from one decimal digit to the next • Useful for reducing errors in communication. • Can be scaled to larger numbers.

  20. ASCII Code • American Standard Code for Information Interchange • ASCII is a 7-bit code, frequently used with an 8th bit for error detection (more about that in a bit).

  21. ASCII Code Most significant bit Least significant bit

  22. ASCII Code e.g., ‘a’ = 1100001

  23. ASCII Code Alphabetic codes

  24. ASCII Code Numeric codes

  25. ASCII Code Punctuation, etc.

  26. ASCII Codes and Data Transmission • ASCII Codes • A – Z (26 codes), a – z (26 codes) • 0-9 (10 codes), others (@#$%^&*….) • Complete listing in Mano text • Transmission susceptible to noise • Typical transmission rates (1500 Kbps, 56.6 Kbps) • How to keep data transmission accurate?

  27. P Information Bits Parity Codes • Parity codes are formed by concatenating a parity bit, P to each code word of C. • In an odd-parity code, the parity bit is specified so that the total number of ones is odd. • In an even-parity code, the parity bit is specified so that the total number of ones is even. • 1 1 0 0 0 0 1 1 •  • Added even parity bit • 0 1 0 0 0 0 1 1 •  • Added odd parity bit

  28. Parity Code Example • Concatenate a parity bit to the ASCII code for the characters 0, X, and = to produce both odd-parity and even-parity codes.

  29. Binary Data Storage • Binary cells store individual bits of data • Multiple cells form a register. • Data in registers can indicate different values • Hex (decimal) • BCD • ASCII 0 0 1 0 1 0 1 1 Binary Cell

  30. Register A Register B Register C Digital Logic Circuits Register Transfer • Data can move from register to register. • Digital logic used to process data • We will learn to design this logic

  31. Transfer of Information • Data input at keyboard • Shifted into place • Stored in memory NOTE: Data input in ASCII

  32. Building a Computer • We need processing • We need storage • We need communication • You will learn to use and design these components.

  33. Summary • 2’s complement most important (only 1 representation for zero). • Important to understand treatment of sign bit for 1’s and 2’s complement. • Although 2’s complement most important, other number codes exist • ASCII code used to represent characters (including those on the keyboard) • Registers store binary data

More Related