Download presentation
Presentation is loading. Please wait.
Published byAugust Casey Modified over 9 years ago
1
Digital Logic Design Lecture 3 Complements, 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
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 (2 n -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. 00001100 2 = 12 10 Sign bitMagnitude 11110100 2 = -12 10 Sign bitMagnitude
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 -2 n-1 <= N <= 2 n-1 -1 where n is the number of bits available for representing N. Note that 2 n-1 -1 = (011..11) 2 and –2 n-1 = (100..00) 2 oFor 2’s complement more negative numbers than positive. oFor 1’s complement two representations for zero. oFor an n bit number in base (radix) z there are z n different unsigned values. (0, 1, …z n-1 )
8
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 = 01100 2 in 1’s comp. (1) 10 = +(0001) 2 = 00001 2 in 1’s comp. 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 Step 1: Add binary numbers Step 2: Add carry to low-order bit Add
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 = 01100 2 in 1’s comp. (-1) 10 = -(0001) 2 = 11110 2 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 Add carry Final Result Step 1: Take 1’s complement of 2 nd operand Step 2: Add binary numbers Step 3: Add carry to low order bit 1’s comp Add
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 = 01100 2 in 2’s comp. (1) 10 = +(0001) 2 = 00001 2 in 2’s comp. 0 1 1 0 0 +0 0 0 0 1 -------------- 0 0 1 1 0 1 Final Result Step 1: Add binary numbers Step 2: Ignore carry bit Add 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 = 01100 2 in 2’s comp. (-1) 10 = -(0001) 2 = 11111 2 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 Final Result Step 1: Take 2’s complement of 2 nd operand Step 2: Add binary numbers Step 3: Ignore carry bit 2’s comp Add Ignore Carry
12
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. 0 1 1 0 1 +1 1 0 1 1 -------------- 10 1 0 0 0 carry
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
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. 0 1 1 0 1 +1 1 0 1 1 -------------- 10 1 0 0 0 carry
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
°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. Data Representation and Communication
17
BCD DigitBit pattern 00000 10001 20010 30011 40100 50101 60110 70111 81000 91001 Note: the following 6 bit patterns are not used: 1010 1011 1100 1101 1110 1111 °Binary Coded Decimal (BCD) represents each decimal digit with four bits Ex. 0011 0010 1001 = 329 10 °This is NOT the same as 001100101001 2 °Why do this? Because people think in decimal.
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. DigitBinary Gray Code 0 0000 1 0001 2 0010 0011 3 0010 4 0100 0110 5 0101 0111 6 0110 0101 7 0111 0100 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 1100 1010 13 1101 1011 14 1110 1001 15 1111 1000
20
ASCII Code °American Standard Code for Information Interchange °ASCII is a 7-bit code, frequently used with an 8 th bit for error detection (more about that in a bit). CharacterASCII (bin) ASCII (hex) DecimalOctal A10000014165101 B10000104266102 C10000114367103 … Z a … 1 ‘
21
21 Most significant bit Least significant bit ASCII Code
22
22 e.g., ‘ a ’ = 1100001 ASCII Code
23
23 Alphabetic codes ASCII Code
24
24 Numeric codes ASCII Code
25
25 Punctuation, etc. ASCII Code
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
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. Information BitsP 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. CharacterASCII Odd-Parity ASCII Even-Parity ASCII 001100001011000000110000 X10110000101100011011000 =01111001011110000111100
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 Binary Cell 00101011
30
Register Transfer °Data can move from register to register. °Digital logic used to process data °We will learn to design this logic Register ARegister B Register C Digital Logic Circuits
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
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.