Binary Arithmetic CPSC 101: Chp 2 John Lamertina
Early Need to Count
One-to-One Sets 27 pebbles ≡ 27 sheep |||||||||||||||||||||||||||||
Counting in 10s Up to TEN More than TEN?
Countable Sets of
Why Decimal Numbers? 10 fingers 10 digits (0,1,2,3,…,9) Countable Sets of 10 Ones Ones Tens Tens Hundreds Hundreds Thousands Thousands etc etc
Simple Decimal Number 27 = = 2 tens + 7 ones = (2×10) + (7×1) = (2×10 1 ) + (7×10 0 ) Powers of 10 Anything to the zero power is 1
9327 = = 9 thousands + 3 hundreds + 2 tens + 7 ones = (9×1000) + (3×100) + (2×10) + (7×1) = (9×10 3 ) + (3×10 2 ) + (2×10 1 ) + (7×10 0 ) Another Decimal Number Powers of 10
7009 = = 7 thousands + 0 hundreds + 0 tens + 9 ones = (7×1000) + (0×100) + (0×10) + (9×1) = (7×10 3 ) + (0×10 2 ) + (0×10 1 ) + (9×10 0 ) A Decimal Number with Zeros Powers of 10
Decimal vs Binary Decimal numbers are powers of 10 Deci = 10 Binary numbers are powers of 2 Bi = 2
Why Binary Numbers? Electronic circuits have two possible states or values: Off and On Off and On: Zero and One (0, 1) Two digits (0, 1): binary number system Thus computers operate on the binary number system
Simple Binary Number = = (1×2 2 ) + (0×2 1 ) + (1×2 0 ) Powers of 2 Read “101, base 2” not 101 squared.
Simple Binary Number = = (1×2 2 ) + (0×2 1 ) + (1×2 0 ) = = = 5 10
Simple Decimal Number vs Simple Binary Number 15 = = 1 ten + 5 ones = (1×10) + (5×1) = (1×10 1 ) + (5×10 0 ) = = (1×2 3 ) + (1×2 2 ) + (1×2 1 ) + (1×2 0 ) = = Powers of 10 Powers of 2
Convert Binary to Decimal (1×2 7 ) + (0×2 6 ) + (1×2 5 ) + (1×2 4 ) + (0×2 3 ) + (1×2 2 ) + (0×2 1 ) + (1×2 0 ) = = Digit Exponent Power of Decimal
Convert Decimal to Binary: “Successive Division by Two” Divide by 2 RemainderExplanation 29 29: starting decimal number 14 29/2 = 14, remainder of /2 = 7, remainder of 0 3 7/2= 3, remainder of 1 3/2 = 1, remainder of 1 Binary Result : Example Decimal Number: 29