Programming and Graphics

(Kiana) #1

6 Introduction to C++ Programming and Graphics


Bytes

Byte 8bits 20 =
Kilobyte (Kbyte) 210 = 1024Bytes 210 = 1024
Megabyte (Mbyte) 210 = 1024Kbytes 220 =1, 048 , 576
Gigabyte (Gbyte) 210 = 1024Mbytes 230 =1, 073 , 741 , 824
Terabyte (Gbyte) 210 = 1024Gbytes 240 =1, 099 , 511 , 627 , 776
Petabyte (Pbyte) 210 = 1024Tbytes 250 =1, 125 , 899 , 906 , 842 , 624
Exabyte (Ebyte) 210 = 1024Pbytes 260  1 , 152 , 921 , 504 , 606 , 847 , 000

Table 1.2.1Large units of bytes. Each byte consists of eight bits.


One byte is sometimes divided into two groups of four bits called nibbles.
Thus, a nibble is half a byte.


Decimal to binary conversion


To express the decimal number 6.28125 in the binary system, we first
consider the integral part, 6, and compute the ratios:


6
2

=3+


0


2


,


3


2


=1+


1


2


,


1


2


=0+


1


2


. (11)


We stop when the integral part has become equal to zero. Collecting the nu-
merators on the right-hand sides expressing the remainderin reverse order,we
find


(6) 10 = (110) 2 =1× 22 +1× 21 +0× 20. (12)

Next, we consider the decimal part and compute the products:


0. 28125 ×2=0. 5625 ,
0. 56250 ×2=1. 1250 ,
0. 56250 ×2=1. 1250 ,
0. 12500 ×2=0. 2500 , (13)
0. 25000 ×2=0. 5000 ,
0. 50000 ×2=1. 0000.

We stop when the decimal part has become equal to zero. Taking the integer
bold-faced figuresin forward order, we find


(0.28125) 10 =(.01001) 2. (14)

Now combining the integral and decimal representations, we find


(6.28125) 10 = (110.01001) 2. (15)
Free download pdf