Programming and Graphics

(Kiana) #1

22 Introduction to C++ Programming and Graphics


Problems


1.6.1.Derive the floating-point representation in single precision with a hidden
bit of (a) -2.00, (b) -0.50, and (c) -2.50.


1.6.2.Find the number whose floating-point representation in single precision
with a hidden bit is:


1 100 0000 0100 1001 0000 1111 1101 1011

1.7 The hexadecimal system.......................


A number in the hexadecimal system is denoted as


(hkhk− 1 ···h 0 .h− 1 ···h−l) 2 (36)

wherekandlare two integers, the hexadecimal characters,hi, take sixteen
values, 0–15, and the period (.) is the hexadecimal point. For convenience, the
six two-digit numbers, 10–15, are represented by the letters A–F.


The corresponding decimal value is

hk× 16 k+hk− 1 × 16 k−^1 +···+h 0 × 160
+h− 1 × 16 −^1 +···+h−l× 16 −l. (37)

Table 1.1.2 shows the hexadecimal representation of zero and first seventeen
integers.


It is easy to find the hexadecimal string of a given binary string. Starting
from the left or right or the binary point, we divide the binary string into blocks
of four digits, and look up the hexadecimal digit corresponding to each block
according to Table 1.1.2. For example,


(101111) 2 = (2F) 16. (38)

The backward translation from hexadecimal to binary can also readily be per-
formed using a similar method.


In C++, hexadecimal numbers are designated by the prefix 0x. Thus, we
write


(101111) 2 = (2F) 16 .=0x2F (39)

Storing and retrieving data


Since one byte can hold two hexadecimal digits, the hexadecimal repre-
sentation is ideal for storing and retrieving data. Consider the floating-point

Free download pdf