250 likes | 411 Views
Binary Arithmetic. Kuliah Sistem Digital, Teknik Elektro UMY (Rahmat Adiprasetya). Introduction.
E N D
Binary Arithmetic Kuliah Sistem Digital, Teknik Elektro UMY (Rahmat Adiprasetya)
Introduction • Due to the fact that digital computers are constructed from logic gates that can represent only two states, they are obliged to make use of the binary number system with its two digits: 0 and 1. • Unlike calculations on paper where both decimal and binary numbers can be of any size — limited only by the size of your paper, the endurance of your pencil, and your stamina — the numbers manipulated within a computer have to be mapped onto a physical system of logic gates and wires. • Thus, the maximum value of a number inside a computer is dictated by the width of its data path; that is, the number of bits used to represent that number.
Unsigned Binary Numbers • Unsigned binary numbers can only be used to represent positive values.
Unsigned Binary Numbers (1) • Each ‘x’ character represents a single bit; the right-hand bit is known as the least significant bit (LSB) because it represents the smallest value. • Similarly, the left hand bit is known as the most significant bit (MSB) because it represents the largest value. • In computing it is usual to commence indexing things from zero, so the least significant bit is referred to as bit 0, and the most significant bit (of an 8-bit value) is referred to as bit 7. • Every bit can be individually assigned a value of 0 or 1, so a group of 8 bits can be assigned 28 = 256 unique combinations of 0s and 1s. • This means that an 8-bit unsigned binary number can be used to represent values in the range 010 through +25510.
Binary Addition • Two binary numbers may be added together using an identical process to that used for decimal addition.
Binary Subtraction • Unsigned binary numbers may be subtracted from each other using an identical process to that used for decimal subtraction. • However, for reasons of efficiency, computers rarely perform subtractions in this manner; instead, these operations are typically performed by means of complement techniques. • There are two forms of complement associated with every number system, the radix complementand the diminished radix complement, where radix refers to the base of the number system. • Under the decimal (base-10) system, the radix complement is also known as the tens complement and the diminished radix complement is known as the nines complement.
Binary Subtraction (nines complement technique) The advantage of the nines complement technique is that it is never necessary to perform a borrow operation.
Binary Subtraction (tens complement technique) The advantage of the tens complement is that it is not necessary to perform an end-around-carry; any carry-out resulting from the addition of the most significant digits is simply dropped from the final result.
Binary Subtraction (Cont.) • Similar techniques may be employed with binary (base-2) numbers, where the radix complement is known as the twos complement and the diminished radix complement is known as the ones complement.
Binary Subtraction (ones complement technique) In fact, it isn’t even necessary to perform a subtraction, because the ones complement of a binary number can be simply generated by inverting all of its bits; that is, by exchanging all the 0s with 1s and vice versa.
Binary Subtraction (Cont.) • Unfortunately, all of the previous examples will return incorrect results if a larger value is subtracted from a smaller value; that is, for these techniques to work, the final result must be greater than or equal to zero. • In the case of unsigned binary numbers, the reason is clear because, by definition, an unsigned binary number can only be used to represent a positive value, but subtracting a larger value from a smaller value results in a negative value. • It would obviously be somewhat inconvenient if computers could only be used to generate positive values, so we need some way to represent negative numbers.
Signed Binary Numbers • Signed binary numbers can be used to represent both positive and negative values, and they do this in a rather cunning way. • In standard decimal arithmetic, negative numbers are typically represented in a form known as sign-magnitude,which means prefixing values with plus or minus signs. • However, for reasons of efficiency, computers rarely employ the sign-magnitude form, and instead use the signed binary format, in which the most significant bit is also called the sign bit
Signed Binary Numbers (3) • Now pay attention because this is the clever part: • closer investigation reveals that each bit pattern is in fact the twos complement of the other! To put this another way, taking the twos complement of a positive signed binary value returns its negative equivalent and vice versa. • The end result is that using signed binary numbers greatly reduces the complexity of operations within a computer.
Binary Multiplication • One technique for performing multiplication in any number base is by means of repeated addition. • However, even though computers can perform millions of operations every second, the repeated addition technique is time-consuming when the values to be multiplied are large. • As an alternative, binary numbers may by multiplied together by means of a shift-and-add technique known as Booth’s Algorithm • Using Booth’s algorithm, a partial product is generated for every bit in the multiplier. If the value of the multiplier bit is 0, its corresponding partial product consists only of 0s; if the value of the bit is 1, its corresponding partial product is a copy of the multiplicand.
Binary Multiplication (Booth’s Algorithm) • Unfortunately, Booth’s Algorithm only works with unsigned binary values. • However, this problem can be overcome by taking the twos complement of any negative values before feeding them into the multiplier. • If the signs of the two values are the same, both positive or both negative, then no further action need be taken. • However, if the signs are different, then the result returned from the multiplier must be negated by transforming it into its twos complement.