Chapter 2 Data Representation
OBJECTIVES After reading this chapter, the reader should be able to: Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images, video, and audio. Work with hexadecimal and octal notations.
2.1 DATA TYPES
Different types of data Figure 2-1 Different types of data
Note: The computer industry uses the term “multimedia” to define information that contains numbers, text, images, audio, and video.
2.2 DATA INSIDE THE COMPUTER
Figure 2-2 Bit pattern
Examples of bit patterns Figure 2-3 Examples of bit patterns
2.3 REPRESENTING DATA
Representing symbols using bit patterns Figure 2-4 Representing symbols using bit patterns
Table 2.1 Number of symbols and bit pattern length 4 8 16 … 128 256 65,536 Bit Pattern Length --------------------- 1 2 3 4 … 7 8 16
Representation of the word Figure 2-5 Representation of the word “BYTE” in ASCII code
Unicode 16 bits e.g. 趙(8D99) 坤(5764) 茂(8302)
http://www.unicode.org/
http://www.cns11643.gov.tw/seeker/chinese/search.jsp
http://www-atm.physics.ox.ac.uk/user/iwi/charmap.html
Image representation methods Figure 2-6 Image representation methods
Bitmap graphic method of a black-and-white image Figure 2-7 Bitmap graphic method of a black-and-white image
Representation of color pixels Figure 2-8 Representation of color pixels
Figure 2-9 Audio representation
2.4 HEXADECIMAL NOTATION
Note: A 4-bit pattern can be represented by a hexadecimal digit, and vice versa.
Table 2.2 Hexadecimal digits Bit Pattern ------------ 0000 0001 0010 0011 0100 0101 0110 0111 Hex Digit ------------ 1 2 3 4 5 6 7 Bit Pattern ------------ 1000 1001 1010 1011 1100 1101 1110 1111 Hex Digit ------------ 8 9 A B C D E F
Binary to hexadecimal and hexadecimal to binary transformation Figure 2-10 Binary to hexadecimal and hexadecimal to binary transformation
Example 1 Show the hexadecimal equivalent of the bit pattern 1100 1110 0010. Solution Each group of 4 bits is translated to one hexadecimal digit. The equivalent is xCE2.
Show the hexadecimal equivalent of the bit pattern 0011100010. Example 2 Show the hexadecimal equivalent of the bit pattern 0011100010. Solution Divide the bit pattern into 4-bit groups (from the right). In this case, add two extra 0s at the left to make the number of bits divisible by 4. So you have 000011100010, which is translated to x0E2.
Example 3 What is the bit pattern for x24C? Solution Write each hexadecimal digit as its equivalent bit pattern to get 001001001100.
2.5 OCTAL NOTATION
A 3-bit pattern can be represented by an octal digit, and vice versa. Note: A 3-bit pattern can be represented by an octal digit, and vice versa.
Table 2.3 Octal digits Bit Pattern ------------ 000 001 010 011 Oct Digit ------------ 1 2 3 Bit Pattern ------------ 100 101 110 111 Oct Digit ------------ 4 5 6 7
Binary to octal and octal to binary transformation Figure 2-11 Binary to octal and octal to binary transformation
Example 4 Show the octal equivalent of the bit pattern 101110010. Solution Each group of 3 bits is translated to one octal digit. The equivalent is 0562, o562, or 5628.
Show the octal equivalent of the bit pattern 1100010. Example 5 Show the octal equivalent of the bit pattern 1100010. Solution Divide the bit pattern into 3-bit groups (from the right). In this case, add two extra 0s at the left to make the number of bits divisible by 3. So you have 001100010, which is translated to 1428.
Write each octal digit as its equivalent bit pattern to get 010100. Example 6 What is the bit pattern for 248? Solution Write each octal digit as its equivalent bit pattern to get 010100.
一個小小的問題 Oct-這個字根代表8; Dec-這個字根代表10,為什麼October 不是八月而是十月?為什麼 December不是十月而是十二月?
因為插入了七月和八月 July源於凱撒(Julius Caesar) 之名,凱撒原是一位有名的羅馬將領,後來當了羅馬皇帝。在這之前就有曆法,那時是以March 為一年的開端,而July是第十五個月;到了凱撒當皇帝便修改曆法,將一年的開始訂為January,而將July 提升到第七位,這個改變一直沿用至今。 凱撒大帝之後,他的兒子奧古斯都(Augustus)繼承王位,人們尊稱他為Augustus,其意義乃代表高貴 (Noble),於是他學凱撒將他的幸運月,以自己的封號命名,並從二月挪一天過來,變成三十一日。 那二月為什麼只有二十八天呢?
二月被砍過兩天 二月為什麼通常只有二十八天? 凱撒(Julius Caesar) 修改曆法時,本來規定每年十二個月裡,逢單是大月三十一日,逢雙是小月三十日,但是這樣算下來,一年就變成三百六十六日,所以必須設法在一年中扣去一天。那時候判處死刑的人犯均在二月分執行,因此人們認為二月是不吉利的月分,既然要扣除一天,那麼就由二月分來扣掉,讓不吉利的日子減少一天,因此二月分就成了二十九日。 後來奧古斯都(Augustus)繼凱撒之後當了羅馬皇帝,他發現凱撒是七月生的,而七月是逢單為大月三十一日;他不服氣,為了表示自己也偉大,就把自己八月出生的月分改為大月三十一日。糟了又多出一天怎麼辦?那還是由二月分來扣除,因此結果二月分就變成二十八日。