1 Foundations of Computer Science Chapter 2 Data Representation
2 Outline 2.1 Data type 2.2 Data inside the computer 2.3 Representing data 2.4 Hexadecimal Notation 2.5 Octal Notation
3 2.1 Data Types 2.1 Data Types
4 Different Types of Data Data TextNumberImageAudioVideo Numbers, text, images, audio, and video are all forms of data. Computers need to process all types of data.
5 Multimedia The computer industry uses the term “multimedia” ( 多媒體 ) to define Information that contains numbers, text, images, audio, and video.
6 2.2 Data Inside The Computer 2.2 Data Inside The Computer
7 Bit Pattern All data types from outside a computer are transformed into a uniform representation called a bit pattern for processing by computers. A bit is the smallest unit of data that can be stored in a computer
8 Bit Pattern A bit pattern of length 8 is called a byte Byte also been used to measure the size of memory or other storage devices 1 byte = 8 bits 1 KB = 1024 bytes 1 MB = 1024 KB 2 bytes = 16 bits 1 GB = 1024 MB K : kilo ( 千 ) M: mega ( 百萬 ) G: giga ( 十億 ) 2 10 = 1024
9 Bit Pattern A switch, with its two states of on and off, can represent a bit(0 or 1) A bit pattern is a sequence of bits that can represent a symbol
10 Examples of Bit Patterns Data are coded ( 邊碼 ) when they enter a computer and decoded ( 解碼 ) when they are presented to the user
Representing Data 2.3 Representing Data
12 Representing Symbols Using Bit Patterns How many bits are needed in a bit pattern to represent a symbol in a language? Depend on how many symbols are in the set
13 Number of Symbols and Bit Pattern Length Number of Symbols Number of Symbols … … 65,536 Bit Pattern Length Bit Pattern Length … 7 8 … 16
14 Codes Code: different sets of bit patterns have been designed to represent text symbols – ASCII: popular code for symbols – EBCDIC: used in IBM mainframes – Unicode ( 萬國碼 ): 16-bit code, allow a greater number of symbols – ISO: 32-bit code, allow a greater number of symbols
15 Coding Coding is the process of transforming data into a bit pattern
16 ASCII American Standard Code for Information Interchange ( 美國資訊交換標準碼 ) The code be developed from the American National Standards Institute (ANSI, 美國國 家標準局 ) ASCII uses 7 bits for each symbol 2 7 = 128
17 Some Features of ASCII ASCII uses a 7-bit pattern: ~ null character; delete character There are 31 control (nonprintable) characters The numeric characters (0~9) are coded before letters
18 Some Features of ASCII There are several special printable characters The uppercase letters (A~Z) come before the lowercase letters (a~z) The upper and lowercase characters are distinguished by only 1 bit. (A ; a ) There are six special characters between the upper and lowercase letters
19 Extended ASCII To make the size of each pattern 1 byte (8 bits), the ASCII bit patterns are augmented with an extra 0 at the left. Extended ASCII uses a 8-bit pattern: ~
20 EBCDIC Extended Binary Coded Decimal Interchange Code ( 延伸的二進位十進制交 換碼 ) EBCDIC uses 8 bits for each symbols Only uses in IBM mainframes 2 8 = 256
21 Unicode Unicode ( 萬國碼 ) be designed from a coalition of hardware and software manufacturers Unicode uses 16 bits and can represent up to 65,536 (2 16 ) symbols
22 ISO International Organization for Standardization ( 國際標準化組織 ) ISO uses 32 bits and can represent up to 4,294,967,296 (2 32 ) symbols
23 Number Numbers are represented using the binary system Chapter 3
24 Images Images today are represented in a computer by one of two methods – Bitmap graphic ( 位元圖、點陣圖 ) – Vector graphic ( 向量圖 ) Image BitmapVector
25 Bitmap Graphic Image is divided into a matrix of pixels ( 像 數:圖畫元素 ), each pixel is assigned a bit pattern The size of the pixel depends on what is called the resolution ( 解析度 )
26 Representation of Color Pixels
27 Color and Gray-layer Images Color image RGB : 3 bytes Resolution: 512 * 512 = 26,624 pixels Image size: 512 * 512 * 3 = 79,872 bytes Gray-layer Image Gray-layer : 1 byte Resolution : 512 * 512 = 26,624 pixels Image size: 512 * 512 * 1 = 26,624 bytes
28 Vector Graphic If you want to rescale the bitmap graphic image, which creates a ragged or grainy look An image is decomposed into a combination of curves ( 曲線 ) and lines ( 直 線 ) Each curve or line is represented by a mathematical formula ( 數學方程式 ) Each time an image is drawn, the formula is reevaluated
29 Audio Audio data are transformed to bit patterns through sampling ( 取樣 ), quantization ( 量化 ), and coding ( 編碼 )
30 Video Video is a representation of images (called frames) in time, the combination of the images represents the video A movie is a series of frames shown one after another to create the illusion of motion Today video is normally compressed: MPEG
Hexadecimal Notation 2.4 Hexadecimal Notation
32 Hexadecimal Notation People find it difficult to manipulate bit patterns. Writing a long stream of 0s and 1s is tedious and prone to error A 4-bit pattern can be represented by a hexadecimal ( 十六進位 ) digit
33 Hexadecimal Digit Bit Pattern Bit Pattern Hex Digit Hex Digit Bit Pattern Bit Pattern Hex Digit Hex Digit A B C D E F
34 Binary to Hexadecimal and Hexadecimal to Binary Transformation F C E ABCDEF89ABCDEF → xFCE4 → XFCE4 → FCE4 16
35 Example BinaryHexadecimal ? ? ?x24C ABCDEF89ABCDEF
36 Example BinaryHexadecimal xCE x0E x24C ABCDEF89ABCDEF
37 Octal Notation A 3-bit pattern can be represented by a octal ( 八進位 ) digit
38 Octal Digit Bit Pattern Bit Pattern Octal Digit Octal Digit Bit Pattern Bit Pattern Octal Digit Octal Digit
39 Binary to Octal and Octal to Binary Transformation → → o →
40 Example BinaryOctal ? ? ?o
41 Example BinaryOctal o o o
42 The End