Binary Numbers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm Harder. All rights reserved. ECE 204 Numerical Methods for Computer Engineers
Binary Numbers This topic introduces binary numbers –standard notation –scientific notation –addition –multiplication
Binary Numbers Decimal numbers are convenient for humans because we have 10 fingers (also called “digits”) Otherwise, they are exceptionally useless as 10 has only two divisors: 2 and 5 Even our day is more conveniently broken up into base 12 which has four divisors: 2, 3, 4, and 6
Binary Numbers Representing ten digits is exceptionally inconvenient for computers It is easiest to represent just two digits with closed and open circuits ( 5 V and 0 V ) We use 0 and 1 to represent these two binary digits, or bits
Binary Numbers We represent a binary integer as a sequence of bits b n b n – 1 · · · b 1 b 0 which equals
Binary Numbers For example, represents 1· · · · · ·2 0 = = 42 As another example, represents 1· · · · · · ·2 0 = = 113
Binary Numbers In counting, we always increment the next digit whenever we increment a “1”:
Binary Numbers We use these numbers to represent the integers in the natural order:
Binary Numbers Binary numbers are very convenient for computers, but very inconvenient for humans –for example, how much smaller is than ? –these are 50 and 500, respectively
Binary Numbers Just like decimal real numbers, we can represent a real number as a sequence of bits: b n b n – 1 · · · b 1 b 0. b –1 b –2 b –3 · · · where b n 0 (i.e., b n = 1 ), and n is any integer This represents the number
Binary Numbers We cannot call the point in b n b n – 1 · · · b 1 b 0. b –1 b –2 b –3 · · · a “decimal point”, as this is not a decimal number The generic name for the point is the radix point
Binary Numbers As with decimal digits, we are only concerned with a finite number of bits: b n b n – 1 · · · b 0. b –1 · · · b m where b n = 1, n is any integer and m n This represents the number
Binary Numbers For example, represents 1· · · ·2 –1 + 0·2 –2 + 1·2 –3 = = As another example, represents 1· ·2 –1 + 1·2 –2 + 1·2 –3 + 0·2 –4 + 1·2 –5 = =
Binary Numbers Notice that is differ only by shifting the radix point by two locations This is equivalent to multiply by 2 –2 or dividing by 4 We also see that
Binary Numbers As with decimal numbers, we can represent binary numbers using scientific notation: Any real number can be written as 1.b -1 b -2 b -3 · · · b –m 2 n which often written as 1.b -1 b -2 b -3 ···b –m en
Binary Numbers To differentiate between binary numbers and decimal numbers it is common to add a subscript 2 or subscript 10: = = = = Note that 42/64 =
Binary Numbers To add two binary numbers: –line up the radix points, add the columns, carrying 1 to next column if the sum is greater than 1 : –for example, add = 2 3 and = 2 0 yielding 2 3 =
Binary Numbers Multiplication of numbers in scientific notation is similar, multiply the mantissa and add the exponents –for example, multiply = 2 5 and = 2 –1 yielding 2 4 = 2 5
Binary Numbers We can verify this by converting to decimal numbers: = = where 44 = and 2 5 = = = 35.75
Binary Numbers Thus, we have seen that the mechanics of binary numbers are identical to the mechanics of decimal numbers
Usage Notes These slides are made publicly available on the web for anyone to use If you choose to use them, or a part thereof, for a course at another institution, I ask only three things: –that you inform me that you are using the slides, –that you acknowledge my work, and –that you alert me of any mistakes which I made or changes which you make, and allow me the option of incorporating such changes (with an acknowledgment) in my set of slides Sincerely, Douglas Wilhelm Harder, MMath