1.28k likes | 2.85k Views
Binary Arithmetic. Binary Addition. Example 1: 0 1 0 1 + 0 1 1 0. Addition Rules:. 1. 0 + 0 = 0 + 1 = 1 + 0 = 1 + 1 = 1 + 1 + 1 =. 0. 1. 1. 1. 0. 1. 1. 0 carry 1. 1 carry 1. Example 2: 1 0 1 1 1 + 1 0 0 1 0. 1. 1. 1. 0. 1. 0. 0. 1. OVERFLOW.
E N D
Binary Addition Example 1: 0 1 0 1 + 0 1 1 0 Addition Rules: 1 0 + 0 = 0 + 1 = 1 + 0 = 1 + 1 = 1 + 1 + 1 = 0 1 1 1 0 1 1 0 carry 1 1 carry 1 Example 2: 1 0 1 1 1 + 1 0 0 1 0 1 1 1 0 1 0 0 1 OVERFLOW
Binary Multiplication Example: 1 0 1 X 111 Multiplication Rules: 0 x 0 = 0 x 1 = 1 x 0 = 1 x 1 = 0 0 0 1 0 1 1 1 + 1 0 1 0 1 1 0 1 0 0 1 0 0 0 1 1
Binary Subtraction A computer cannot subtract a number from another. It can only add two numbers Example: Subtract B from A A - B Add –B to A A + (-B) Complementation
Subtraction Rules • Pad with 0’s until both numbers are the same length • Take 2’s complement of the digit to be subtracted • Add the result to the first binary number • Ignore the carry result to preserve the initial size
Step 1: One’s Complement Example: Find the one’s complement of 1001101 Number 1001101 Invert bits 0110010 Step 2: Two’s Complement Adding 1 to the one’s complement of a binary digit Example: Find the two’s complement of 1001101 Number 1001101 One’s complement 0110010 Add 1 + 1 Two’s complement 0110011
Practice Examples Example 1:Find the result of 101 - 10 Step 1: Two’s complement for 010 Number 010 Invert bits 101 Add 1 + 1 Code for -010 = 110 Step 2: Add answer with first number Number 101 Code for -010 = 110 011