* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download 1`s complement method
Survey
Document related concepts
Transcript
1’s and 2’s Complements Introduction • Subtraction of a number from another can be accomplished by adding the complement of the subtrahend to the minuend. 1’s Complement Subtraction • Subtraction of binary numbers using the 1’s complement method allows subtraction only by addition. • The 1’s complement of a binary number can be obtained by changing all 1s to 0s and all 0s and 1s. 1’s complement method • To subtract a smaller number from a larger number, the 1’s complement method is as follows 1. Determine 2. 3. Add this the Remove tothe the carry 1’s larger complement andnumber add it to of thethe result. smaller Thisnumber. carry is called end-around-carry Example of 1’s complement Subtract (1010)2 from (1111) 2 1’s complement method Direct Subtraction 1 1 1 1 1 0 1 0 0 1 0 1 1 1 1 1 1’s complement Carry Add Carry 0 1 0 1 1 0 1 0 0 1 0 10 1 Subtraction Steps • Subtraction of a large number a smaller one by the 1’s complement method involves the following steps 1. The 2. 3. Determine Add answer this to the the is the 1’s smaller 1’s complement complement number of of a large the result number and is opposite in sign. There is no carry. 2’s Complement Subtraction • The 2’s complement of a binary number can be obtained by adding 1 to its 1’s complement. Steps • Subtraction of a smaller number from a larger one by the 2’s complement method involves the following steps 1. 2. 3. Determine the (2’s complement the smaller number Add this Omit theto carry larger there number is always of a carry in this case ) Example of 2’s complement Subtract (1010)2 from (1111) 2 Direct Subtraction 2’s complement method 1 1 1 1 1 1 1 1 1 0 1 0 2’s complement 0 1 1 0 0 1 0 1 Carry 1 0 1 0 1 Subtraction Steps • The carry is discarded. Thus answer is (0101)2 • The 2’s complement method for subtraction of a large number from a smaller one is as follows. 1. To 2. 3. Determine Add There the isanno 2’sanswer the carry complement 2’s. in The complement result to the is in smaller of 2’s thecomplement larger number form 4. get true form, take the 2’s number is negative and change the sign. complement Comparison between 1’s and 2’s complements 1’s Complement 2’s Complement It can be easily obtained using an Inverter It has to be arrived at by first obtaining the 1’s complement and then adding one (1) to it It requires two operations Only one arithmetic operation is required It is often used in logical manipulations for inversion operation It is used only for arithmetic applications