Unformatted text preview:

Digital ArithmeticBinary ArithmeticAdding Unsigned NumbersAdding Unsigned NumbersRepresenting Signed NumbersRepresenting Signed Numbers Converting to 2’s Complement2’s Complement Representation More Examples2’s Complement RepresentationArithmetic Operations using 2’s ComplementArithmetic Operations using 2’s ComplementBCD AdditionBCD Addition – Another ExampleHex ArithmeticHex ArithmeticDigital ArithmeticDigital Arithmetic: Operations and CircuitsDr. FarahmandBinary Arithmetic Digital circuits are frequently used for arithmetic operations Fundamental arithmetic operations on binary numbers and digital circuits which perform arithmetic operations will be examined. Binary numbers are added like decimal numbers. In decimal, when numbers sum more than 9 a carry results. In binary when numbers sum more than 1 a carry takes place. Addition is the basic arithmetic operation used by digital devices to perform subtraction, multiplication, and division.If the numbers are unsigned and positive add them as follow: 1 + 0 = 1 with carry of 01 + 1 = 0 with carry of 11 + 1 + 1 = 1 with carry of 1For example: 011.011 +010.110 = 110.001 = 6.125 base 10Adding Unsigned Numbers Examples:X 190 10111110Y 141 10001101X+Y 331 101001011X 127 1111111Y 63 111111X+Y 190 10111110X 170 10101010Y 85 1010101X+Y 255 11111111Adding Unsigned Numbers Examples:X 190 10111110Y 141 10001101X+Y 331 101001011X 127 1111111Y 63 111111X+Y 190 10111110X 170 10101010Y 85 1010101X+Y 255 11111111Representing Signed Numbers Since it is only possible to show magnitude with a binary number, the sign (+ or -) is shown by adding an extra “sign” bit. A sign bit of 0 indicates a positive number. A sign bit of 1 indicates a negative number. The 2’s complement system is the most commonly used way to represent signed numbers.0 1 1 11 0 0 10 0 0 01 1 1 1+70-1-71 0 0 0-8Sign-bitMagnitude bitsExamples of 2’s complement representation+2^0+2^1+2^2-2^3+2 +1+4-8Representing Signed Numbers Converting to 2’s Complement In order to change a binary number to 2’s complement it must first be changed to 1’s complement. To convert to 1’s complement, simply change each bit to its complement (opposite). To convert 1’s complement to 2’s complement add 1 to the 1’s complement. A positive number is true binary with 0 in the sign bit. A negative number is in 2’s complement form with 1 in the sign bit. A binary number can be negated by taking the 2’s complement of it.For example: +9  01001 (sign bit = 0, indicating +)2’s complement of 9 01001  10110 10110 + 1  10111 = -9This is The sign BITWhen the sign-bit is zero  Positive number If the sign-bit is set  Negative numberRemember: 2’s complement is just a conventional way of representing signed numbers in digital arithmetic – Don’t ask why!2’s Complement Representation  Assuming N+1 bits representing a 2’s Complement (that is representing the number with N bits and one bit is dedicated to indicate the sign): Largest positive number will be 2N-1 Smallest signed number (largest negative number) will be -2N Total numbers (including zero) that can be represented will be 2N+1For example:Assume 3+1 bitsLargest pos. number will be 0111= +7Smallest number will be 1000 = -8Remember: 1111= -1Zero is represented by 0000 = ZeroFor example:Assume 6+1 bitsLargest pos. number will be ?? Smallest signed number will be ??Zero is represented by ??0 111 111 = 631 000 000 = -640 000 000 = 0More ExamplesInteger2's ComplementSigned Unsigned5 5 0000 01014 4 0000 01003 3 0000 00112 2 0000 00101 1 0000 00010 0 0000 0000-1 255 1111 1111-2 254 1111 1110-3 253 1111 1101-4 252 1111 1100-5 251 1111 1011Integer2's ComplementSigned7 01116 01105 01014 01003 00112 00101 00010 0000-1 1111-2 1110-3 1101-4 1100-5 1011-6 1010-7 1001-8 1000Remember: Always know how many bits are provided!2’s Complement RepresentationInteger2's ComplementSigned7 01116 01105 01014 01003 00112 00101 00010 0000-1 1111-2 1110-3 1101-4 1100-5 1011-6 1010-7 1001-8 1000Arithmetic Operations using 2’s Complement Inverting A positive number to a negative number  A negative number to a positive number  Either case just take the 2’s complement Adding A and B A+B (assuming N bits represent the magnitude and one bit is dedicated as the sign-bit) Subtracting B from A  A-B Just take the 2’s Complement of B  Add A and B (A+B)X 180 10110100Y 85 01010101X+Y 265 100001001X 6 0110Y -3 1101X-Y 3 1 0011X 4 0100Y -7 1001X-Y -3 1101X -3 1101Y -6 1010X+Y -9 1 0111X 7 0 111Y 7 0 111X+Y 141 110Magnitude Overflow:(max unsigned number that can be represented using 8 bits is 255)The carry will be ignoredOverflow:(max signed number that can be represented using 4 bits is -8)Overflow:(max signed number that can be represented using 4 bits is 7)Note the value is negativeArithmetic Operations using 2’s Complement Inverting A positive number to a negative number  A negative number to a positive number  Either case just take the 2’s complement Adding A and B A+B (assuming N bits represent the magnitude and one bit is dedicated as the sign-bit) Subtracting B from A  A-B Just take the 2’s Complement of B  Add A and B (A+B) NOTE: When a Positive and a Negative number are added together, the overflow will be a signed overflow and it is ok! X 180 10110100Y 85 01010101X+Y 265 100001001X 6 0110Y -3 1101X-Y 3 1 0011X 4 0100Y -7 1001X-Y -3 1101X -3 1101Y -6 1010X+Y -9 1 0111X 7 0 111Y 7 0 111X+Y 141 110Magnitude Overflow:(max unsigned number that can be represented using 8 bits is 255)The carry will be ignoredOverflow:(max signed number that can be represented using 4 bits is -8)Overflow:(max signed number that can be represented using 4 bits is 7)Note the value is negativeX -4 11100Y -9 10111X+Y -131 10011The overflow can be discarded when it is sign overflow (max = -16):BCD Addition BDC numbers  They are between 0 and 9 Hence each decimal number is represented by 4 bits Add each number between 0-9 individually  0 1 1 0  BCD for 60 1 1 1  BCD for 7_________________1 1 0 1  13 but invalid! 0 1 1 0  Add 6 to correct________________________0 0 0 1 0 0 1 1  BDC for 13!!BCD Addition – Another Example BDC numbers  They are between 0 and 9 Hence each decimal number is represented by 4 bits Add each number between 0-9 individually 10 1 0 1 1


View Full Document

SSU ES 310 - Digital Arithmetic

Download Digital Arithmetic
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Digital Arithmetic and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Digital Arithmetic 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?