binary numbers douglas wilhelm harder department of electrical and computer engineering university...

21
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

Upload: buck-whitehead

Post on 01-Jan-2016

220 views

Category:

Documents


2 download

TRANSCRIPT

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

bn bn – 1 · · · b1 b0

which equals

n

k

kkb

0

2

Binary Numbers

• For example, 101010 represents

1·25 + 0·24 + 1·23 + 0·22 + 1·21 + 0·20

= 32 + 16 + 2 = 42

• As another example, 1110001 represents

1·26 + 1·25 + 1·24 + 0·23 + 0·22 + 0·21 + 1·20

= 64 + 32 + 16 + 1 = 113

Binary Numbers

• In counting, we always increment the next digit whenever we increment a “1”:

1

10

11

100

101

110

111

1000

1001

1010

1011

1100

Binary Numbers

• We use these numbers to represent the integers in the natural order:

1 1

10 2

11 3

100 4

101 5

110 6

111 7

1000 8

1001 9

1010 10

1011 11

1100 12

Binary Numbers

• Binary numbers are very convenient for computers, but very inconvenient for humans– for example, how much smaller is 110010

than 111110100?– these are 50 and 500, respectively

Binary Numbers

• Just like decimal real numbers, we can represent a real number as a sequence of bits:

bn bn – 1 · · · b1 b0 . b–1 b–2 b–3 · · ·

where bn 0 (i.e., bn = 1), and n is any integer

• This represents the number

n

k

kkb 2

Binary Numbers

• We cannot call the point in

bn bn – 1 · · · b1 b0 . 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:

bn bn – 1 · · · b0 . b–1 · · · bm

where bn = 1, n is any integer and m n

• This represents the number

n

mk

kkb 2

Binary Numbers

• For example, represents

1·22 + 0·21 + 1·20 + 1·2–1 + 0·2–2 + 1·2–3

= 4 + 1 + 0.5 + 0.125

= 5.625

• As another example, represents

1·20 + 0·2–1 + 1·2–2 + 1·2–3 + 0·2–4 + 1·2–5

= 1 + 0.25 + 0.125 + 0.03125

= 1.40625

Binary Numbers

• Notice that 101.101 is 1.01101 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 2n

which often written as 1.b-1b-2b-3···b–men

Binary Numbers

• To differentiate between binary numbers and decimal numbers it is common to add a subscript 2 or subscript 10:

1010102 = 4210

0.101012 = 0.6562510

11111010002 = 100010

100000000002 = 102410

• Note that 42/64 = 0.65625

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

1011.1 = 1.0111 23

and

1.1101 = 1.0111 20

yielding 1.1010101 23 = 1101.0101

1010101.1

0011101.

0111.11

Binary Numbers

• Multiplication of numbers in scientific notation is similar, multiply the mantissa and add the exponents– for example, multiply

101100 = 1.011 25 and

0.1101 = 1.101 2–1

yielding 10.001111 24

=1.0001111 25 001111.10

011000.1

101100.0

000000.0

001011.0

101.1

011.1

Binary Numbers

• We can verify this by converting to decimal numbers:1011002 = 4410

0.11012 = 0.812510

where 44 0.8125 = 35.75

and 1.0001111 25 = 100011.11

= 32 + 2 + 1 + 0.5 + 0.25

= 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

[email protected]