Programming and Graphics

(Kiana) #1

4 Introduction to C++ Programming and Graphics


and the number ten is the radix of the decimal system. Computers are two-
fingered devices; humans are ten-fingered creatures. The ancient Mayans used
a base-twenty system counting fingers and toes.


In the binary system, a number is denoted as

(bkbk− 1 ···b 0 .b− 1 ···b−l) 2 (1)

wherekandlare two integer indices, the binary digits orbits,bi, take the value
of 0 or 1, and the period (.) is the binary point. The implied value is equal to


bk× 2 k+bk− 1 × 2 k−^1 +···+b 0 × 20
+b− 1 × 2 −^1 +···+b−l× 2 −l. (2)

In the decimal system, the same number is expressed as


(dmdm− 1 ···d 0 .d− 1 ···d−n) 10 , (3)

wheremandnare two integers, the decimal digitsditake values in the range
0 – 9, and. is the decimal point. The subscript 10 is omitted by convention in
everyday exchange. The implied value is equal to


dm× 10 m+dm− 1 × 10 m−^1 +···+d 0 × 100
+b− 1 × 10 −^1 +···+d−n× 10 −n, (4)

which is identical to that computed from the base-two expansion.


As an example, the binary representation of the number 6.28125 is

(6.28125) 10 = (110.01001) 2
=1× 22 +1× 21 +0× 20 +0× 2 −^1 +1× 2 −^2 +0× 2 −^3
+0× 2 −^4 +1× 2 −^5. (5)

In this case,k=2andl= 5. The conversion from decimal to binary will be
discussed later in this section.


Since bits can be represented by the on-off positions of electrical switches
that are built in the computer’s electrical circuitry, and since bits can be trans-
mitted by positive or negative voltage as a Morse code, the binary system is
ideal for developing a computer architecture. However, this convenience comes
at the expense of economy, as a binary string is generally much longer than a
decimal string.


Largest integer encoded by p bits


The largest integer that can be represented withpbits is

(111···111) 2 (6)
Free download pdf