160 likes | 635 Views
Binary Subtraction. borrow. -). Subtracter. A. R. Subtracter. B. b. Arithmetic: Subtraction. 293 – 154 = 139. 293 – 154 = 293 + ( -154). 293 – 154 = 293 + ( 1,000,000 - 154) - 1,000,000. ( 1,000,000 - 154) = 999,846. 099,999 +) 900,000 999,999. +). Positive:
E N D
Binary Subtraction borrow -)
Subtracter A R Subtracter B b
Arithmetic: Subtraction 293 – 154 = 139 293 – 154 = 293 + ( -154) 293 – 154 = 293 + (1,000,000 - 154) - 1,000,000 (1,000,000 - 154) = 999,846 099,999 +) 900,000 999,999 +) Positive: 000,000 ~ 099,999 Negative: 900,000 ~ 999,999 ( -100,000 ~ -1 ) 0: positive 1—8 : not used 9: negative Sign digit
Positive: 000,000 ~ 099,999 Negative: 900,000 ~ 999,999 ( -100,000 ~ -1 ) 10’s Complement X = - 025,980 9’s Complement of X (9+1)’s Complement of X 900,000 – 1 = 899,999 899,999 100,000 -100,000 999,999 – 1 = 999,998 999,998 000,001 -1
Binary Subtraction 0110,0011 – 0001,1100 = 0100,0111 0110,0011 – 0001,1100 = 0110,0011 + ( - 0001,1100) = 0110,0011 + (1,0000,0000 – 0001,1100) – 1,0000,0000 (1,0000,0000 – 0001,1100) = 1110,0100 Positive: 0000,0000 ~ 0111,1111 (0 ~ 127) Negative: 1000,0000 ~ 1111,1111 ( -1000,0000 ~ -0000,0001 ) (-128 ~ -1) Sign bit 0: positive 1: negative
Positive: 0000,0000 ~ 0111,1111 (0 ~ 127) Negative: 1000,0000 ~ 1111,1111 ( -1000,0000 ~ -0000,0001 ) (-128 ~ -1) 2’s Complement X = - 0110,1101 1’s Complement of X (1+1)’s Complement of X 1000,0000 – 1 = 0111,1111 0111,1111 1000,0000 -1000,0000 1111,1111 – 1 = 1111,1110 1111,1110 0000,0001 -1
Complement numbers and Subtraction Let a and b be two unsigned numbers. • Decimal numbers (base 10) • If a is 10’s complement of b, then b is 10’s complement of a. • a - b = a + (the 10’s complement of b) • Binary numbers (base 2) • If a is 2’s complement of b, then b is 2’s complement of a. • a - b = a + (the 2’s complement of b) The 2’s complement of a binary unsigned can be found efficiently.