Chap 1 Number Systems 2001-08-16 - Concordia University

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

1.1 Introduction Given that digital logic and memory devices are based on two

electrical states (on and off), it is natural to use a number system, called the binary number system, which contains only two symbols, namely 0 and 1.

This Chapter begins by introducing conversion between decimal and binary numbers, then treats binary arithmetic. In common practice of using binary numbers, many conventions have been devised, so this chapter also introduces several conventions for manipulating and storing binary numbers, including the IEEE floating-point standard.

COEN 231 Class Notes J.C.Gigu?re & L.M.Landsberger

p 1.1

Number Systems Autumn 2001-2002

1.2 Binary Numbers Positive Integers In order to get some idea of the correspondence between binary numbers and the more familiar decimal numbers, one need only glance at the table below.

Decimal Binary

0

0

1

1

2

10

3

11

4 100

5 101

6 110

20 21 21+20 22 22+20 22+21

7

111 22+21+20

8 1000

23

Decimal Binary

9 1001

21-1

10 1010

11 1011

22-1

12 1100

13 1101

14 1110

15 1111

23-1

16 10000

23+20 23+21 23+21+20 23+22 23+22+20 23+22+21 23+22+21+2 24-1

0

24

Some salient features of the correspondence include: ? a 1 followed by n 0's in binary represents decimal 2n. ? a group of n 1's in binary represents decimal (2n-1).

This is the basic structure of binary arithmetic.

Ex. 1: The decimal number 14 is represented in binary as:

14base 10 = 8 + 4 + 2 + 0 = 1*23 + 1*22 + 1*21 + 0*20 = 1110base 2 = %1110.

The % indicates that we are dealing with a binary number.

It is useful (and easy) to generate a list of powers of 2:

20 = %1

=1

26 = %1000000

=64

21 = %10

=2

27 = %10000000

=128

22 = %100

=4

28 = %100000000

=256

23 = %1000

=8

29 = %1000000000

=512

24 = %10000

=16

210 = %10000000000 =1024

COEN 231 Class Notes J.C.Gigu?re & L.M.Landsberger

p 1.2

Number Systems Autumn 2001-2002

25 = %100000

=32

211 = %100000000000 =2048

Ex. 2: The decimal number 353 is represented in binary as: 353 = 256 + 64 + 32 + 1 = 1*28 + 0*27 + 1*26 + 1*25 + 0*24 + 0*23 + 0*22 + 0*21 + 1*20 =%101100001

Ex. 3: The decimal number 251 is represented in binary as: 251 = 128 + 64 + 32 + 16 + 8 + 2 + 1

= 1*27 + 1*26 + 1*25 + 1*24 + 1*23 + 0*22 + 1*21 + 1*20 = %11111011

An alternative view: If you remember that 256 = 28 = %100000000, then you can notice that 255 = 28-1 = %11111111, and that 251 is 255-4 = 255-22 = %11111011 (simply remove the "1" corresponding to the 22 position.)

Ex. 4: One can use the same idea as in Ex 3 in many cases to convert from binary to decimal: %11011101 = 255 - 25 - 21 = 255 ? 32 ? 2 = 221

Bits and bytes and words Each binary digit is known as a bit. A grouping of 8 binary

digits or bits is known as a byte. Given a fixed number of n bits, known as a word, which the arithmetic unit of a computer is designed to handle, then there are 2n separate binary numbers that can be accommodated. For example, in 8 bits, one can accommodate the binary numbers corresponding to decimal 0 to 255 (256 different numbers).

Current computers have word lengths of 32 or 64 bits.

COEN 231 Class Notes J.C.Gigu?re & L.M.Landsberger

p 1.3

Number Systems Autumn 2001-2002

Fractions Numbers smaller than 1 are represented using negative powers of 2. For reference, the first few negative powers of 2 are:

2-1 = ? 2-2 = ? 2-3 = 1/8 2-4 = 1/16 2-5 = 1/32 2-6 = 1/64 2-7 = 1/128 2-8 = 1/256

= 0.5 = 0.25 = 0.125 = 0.0625 = 0.03125 = 0.015625 = 0.0078125 = 0.00390625

= %0.1 = %0.01 = %0.001 = %0.0001 = %0.00001 = %0.000001 = %0.0000001 = %0.00000001

Note that the number of places to the right of the decimal point is equal to the absolute value of the negative exponent (and is equal to the number of places to the right of the binary point.)

Ex. 5: The decimal number 3.375 is represented in binary as:

3.375 = 2 + 1 + 0.25 + 0.125 = 1*21 + 1*20 +0*2-1 + 1*2-2 + 1*2-3 = %11.011

The fractions 1/3 or 3/7 cannot be represented as terminating decimal numbers, A little thought will lead one to realize that only those fractions whose denominator can be expressed as a power of 2 can be written as a terminating binary number. The binary number representations for ?, ?, 3/8, 9/16, etc. all terminate. However, the binary number representations for 1/3, 1/5, 3/10 etc. need an infinite number of binary digits. The leastsignificant (right-most) bits of these representations must be truncated. As is the case of decimal numbers, we must decide how many digits beyond the binary point we wish to retain.

COEN 231 Class Notes J.C.Gigu?re & L.M.Landsberger

p 1.4

Number Systems Autumn 2001-2002

Division by twos method for decimal to binary conversion A simple way to convert decimal integers to binary numbers is through repeated division by 2 and the saving of remaining 1's and 0's. For example:

Ex. 6: 11 = 2*5+1, 5 = 2*2+1, 2 = 2*1+0, 1 = 2*0+1. Stringing the remainders in reverse order, we get 11 = %1011. This works since: 11 = 2*5+1 and 5 = 2*2+1 so that 11 = 2*(2*2+1)+1. Now 2 = 2*1+0 so that 11 = 2*(2*[2*1+0]+1)+1. Finally, 1 = 2*0+1, so that 11 = 2*(2*[2*{2*0+1}+0]+1)+1

= 23*1+22*0+21*1+20*1.

Ex. 7: Convert 353 to binary format using division by twos.

Number Remainder Number Remainder

353

11

0

176

1

5

1

88

0

2

1

44

0

1

0

22

0

0

1

Taking remainders in reverse order, we get 353 = %101100001.

COEN 231 Class Notes J.C.Gigu?re & L.M.Landsberger

p 1.5

Number Systems Autumn 2001-2002

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download