©Brooks/Cole, 2003 Chapter 2 Data Representation
©Brooks/Cole, 2003 Figure 2-1 Different types of data Computer programs can have different purposes: -Word processing program handles TEXT (move, delete, just) -Engineering program deals with NUMBERS (arithmetic equations,..) -Image processing program manipulate images (create, shrink, rotate,..) -Video player shows movie and handles audio data ( play music, voice.)
©Brooks/Cole, 2003 Figure 2-2 Bit pattern -All data types are represented using universal format called bit pattern which is a sequence or string of bits -A Bit (binary digit) is the smallest unit of data that can be stored in a computer; it is either 0 or 1 -An electronic switch can represent a bit. -Example of a 16 bit pattern -Computer memory stores the data as bit pattern and I/O devices or programs interpret bit patterns as needed into number, text, image, audio, video (multimedia). -Data are coded when they enter the computer and decoded when they are represented to user.
©Brooks/Cole, 2003 Figure 2-3 Examples of bit patterns
©Brooks/Cole, 2003 Figure 2-4 Representing symbols using bit patterns - A piece of TEXT in any language is a sequence of symbols used to represent an idea in that language. -ُ Each symbol can be represented by a bit pattern - TEXT such as BYTE can be represented as 4 bit pattern
©Brooks/Cole, Logarithmic relationship between bit pattern length and number of symbols. Example: 2 symbols needs 1 bit (log 2 2) FormsNumber of Symbols Bit Pattern Length 0, , 01,10, ,001,010,011,100,101,110, ,0001,0010,0011,0100,0101, 0110,0111,1000,1001,1010, ,1101,1110, Representing symbols using bit patterns
©Brooks/Cole, 2003 Figure 2-5 Representation of the word “BYTE” in ASCII code - ASCII is the American Standard Code for Information Interchange and it has the following features: -Uses 7-bit pattern: (null) to (delete). 128 symbols can be represented. -There are 31 nonprintable character -Numeric characters are coded before letters -A, B….Z (upper letters) come before a, b,…., z (lowercase) and the sixth bit from right distinguishes them.
©Brooks/Cole, 2003 Representation of Symbols with other Codes - Extended ASCII uses 8-bits pattern instead of 7-bits to represent 256 symbols. - EBCDIC (Extended Binary Coded Decimal Interchange Code) uses 8-bits but it is only used on IBM computers. - UniCode uses 16-bits to represents 65,535 symbols. - ISO uses 32-bit pattern to represent 4,294,967,294 symbols.
©Brooks/Cole, 2003 Figure 2-6 Image representation methods - Bitmap graphic method divides an image into pixels (picture element which is a small dot. The resolution is the size of the pixels. As the resolution increases, the image quality will increase but more memory will be needed to store the image. - Vector graphics does not store the bit pattern of an image because an image will be represented using a mathematical formula which will be stored. An image is decomposed into a combination of curves and lines. Scaling is very easy.
©Brooks/Cole, 2003 Figure 2-7 Bitmap graphic method of a black-and-white image - Each pixel is assigned a bit pattern (0 for white, 1 for black) To show 4 levels of gray scale, a pixel is represented by a 2-bit pattern(00 black, 01 dark gray, 10 light dark gray, 11white)
©Brooks/Cole, 2003 Figure 2-8 Representation of color pixels - Each colored pixel is decomposed into red, green, blue. - Intensity of each color is measured and a bit pattern ( usually 8-bit) is assigned to it. - More memory is needed to store a colored image!!
©Brooks/Cole, 2003 Figure 2-9 Audio representation 1. Measure value of signal at equal intervals 2. Assign a value from a set to a sample 3. Store converted binary pattern
©Brooks/Cole, 2003 Figure 2-10 Binary to hexadecimal and hexadecimal to binary transformation A 4-bit pattern can be represented by a hexadecimal digit, and vice versa. Bit Pattern Bit Pattern Hex Digit Hex Digit Bit Pattern Bit Pattern Hex Digit Hex Digit A B C D E F
©Brooks/Cole, 2003 Example 1 Show the hexadecimal equivalent of the bit pattern Solution Each group of 4 bits is translated to one hexadecimal digit. The equivalent is xCE2.
©Brooks/Cole, 2003 Example 2 Show the hexadecimal equivalent of the bit pattern 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 , which is translated to x0E2.
©Brooks/Cole, 2003 Example 3 What is the bit pattern for x24C? Solution Write each hexadecimal digit as its equivalent bit pattern to get
©Brooks/Cole, 2003 Figure 2-11 Binary to octal and octal to binary transformation A 3-bit pattern can be represented by an octal digit, and vice versa. Bit Pattern Bit Pattern Oct Digit Oct Digit Bit Pattern Bit Pattern Oct Digit Oct Digit
©Brooks/Cole, 2003 Example 4 Show the octal equivalent of the bit pattern Solution Each group of 3 bits is translated to one octal digit. The equivalent is 0562, o562, or
©Brooks/Cole, 2003 Example 5 Show the octal equivalent of the bit pattern 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 , which is translated to
©Brooks/Cole, 2003 Example 6 What is the bit pattern for 24 8 ? Solution Write each octal digit as its equivalent bit pattern to get