You are on page 1of 5

Lecture 5: Information Representation: • Computers use special formats and standards to store

characters, numbers, images and other types of data.


data types, numeric, text and image data
Two types of data files:
Information: 1. Most data files are binary files
Inside computer all informations are represented digitally • Programs
as sequence of 0s and 1s (low/high voltages, closed/open • Graphics
circuits, pits/bumps, etc). • Audios
• Videos ……
Information includes both
1) data (texts, images, audios, videos, etc.) and 2. Some are text files – containing characters only
2) programs (software). • HTML programs (text)
• Emails (without attachment) ……
-1- -2-

Text File: • ASCII: American Standard Code for Information


Interaction – maps each character to an 8-bit pattern
• Text files use codes (e.g. ASCII & Unicode codes) to
represent all characters (letters, digits, punctuation (Maximum 256 = 28 possible codes – patterns)
marks, special symbols, etc.) and can be read by text
word processors such as Notepad and Word. Text files • A: 01000001 0: 00110000
contain text only (HTML program, emails without B: 01000010 1: 00110001
attachment, etc.). Pictures are not text files. They use C: 01000011 2: 00110010
pixels (bitmap) and must be read by a graphics …. ….
viewer/editor.
(26 upper and 26 lower case characters plus 10 digits
• The basic element of the text file is either an ASCII – totally 62 characters.)
code (8 bits or 1 byte) or a Unicode (16 bits or 2 bytes).
The basic element of a binary file is a bit. (Try
Notepad.)
-3- -4-
e.g. Hello →

0100100001100101011011000110110001101111
H e l l o

• Punctuation and special characters (64 characters)

! “ } + & ∪ ∩ α β ….

• Foreign language characters (Roman-based alphabets),


symbols, control (hidden) codes and others

Ë ä Ő ∀ ∞ …

-5- -6-

• ASCII code does not support languages with more than Binary Files:
256 characters
• The term binary is used to refer to all representations
• Unicode uses 2 bytes (16 bits) – with maximum 65536 aside for ASCII and Unicode, such as graphics,
(216) possible characters programs in executable form, audio files (mp3), video
files (mpeg), etc. Special softwares are used to view,
Supports other languages with larger alphabets – Greek, edit, run or open these files.
Hebrew, Japanese, Chinese, etc.
• Programs: A program consists of a sequence of
E.g. “f” in ASCII and Unicode Æ instructions (commands). An instruction is represented
as a binary code (pattern).
01100110 0000000001100110
(ASCII) (Unicode) e.g.: 0110011001000011 Æ move R3, M(100)
1100000000010011 Æ add R3, 1
0101010000000000 Æ jump M(1024)
-7- -8-
• Images: Thus each pixel is stored as a 3-byte (24-bit) number.

A variety of formats are used. The simplest bitmap A picture partitioned into 1024 by 1024 grid consists
format partitions an image into a grid of tiny dots, of 1024 × 1024 × 3 bytes = 3,145,728 bytes of data.
called pixels (picture elements). The image is then The resolution of the image refers to the number of
stored in a file as an array of colors of the pixels (Fig). pixels used to make up the image. The resolution of
the above image is:
Each color of a pixel is represented by three numbers
corresponding to the RGB (red, green, blue) 1024 × 1024 = 1,048,576 pixels ≅ 1 (megapixels).
components of the color. Each number uses one byte to
represent the intensity of that component (0 ~ 255). The higher the resolution (i.e. the number of pixels),
the sharper and clearer the image, but the larger the
E.g.: red – (255, 0, 0), size of the image file. Therefore there is a tradeoff
black – (0, 0, 0), between the high-resolution and low-resolution
organge – (255, 165, 0) images.
-9- - 10 -

Binary Numbers:

• The computer is a binary system. In order for CPU to


understand the numbers and perform arithmetic
operations on them, numbers must represented in
binary form. If the numbers are stored as text (ASCII
or Unicode), they must be converted to binary before
CPU can process them.

• Binay formats include unsigned magnitude and two’s


complement for integers, and floating-point for
decimal-numbers. (Floating-point numbers are
susceptible to round-off errors.)

- 11 - - 12 -
Decimal vs unsigned binary: • Unsigned binary to decimal conversion:

decimal binary 123 = 1×102 + 2×101 + 3×100 = 100 + 20 + 3


0 0
1 1
2 10
3 11
4 100
5 101
6 110 Binary Æ Decimal:
7 111
8 1000
9 1001
10 1010

Question: Dec. 11 = Bin. ?


- 13 - - 14 -

• Decimal to unsigned binary conversion: • Signed magnitude:


2
2
| 125
| 62 1
2
2
| 19
| 9 1
The first bit is a sign bit (“0” Æ + , “1” Æ −).
2 | 31 0 2 | 4 1
2
2
| 15
| 7
1
1
2
2
| 2
| 1
0
0
e.g. (−15)10 = (1000000000001111)2 (16-bit)
2 | 3 1 (8)10 = (0000000000001000)2 (16-bit)
2 | 1 1 (19)10 = (10011)2

(125)10 = (1111101)2 • ASCII vs binary:

Algorithm for converting decimal (D) to binary (B): 17 Æ 0011000100110111 ( ASCII )


1) Divide D by 2 Æ (Q, R)
2) As long as Q is greater than 1 (Q>1), repeatedly divide Q by 2
17 Æ 10001 ( unsigned binary )
3) When Q is equal to 1 (Q=1), stop. Write down the last quotient
and all the remainders backward. The result is the answer. 17 Æ 0000000000010001
( 16-bit signed magnitude )
- 15 - - 16 -
• Floating-point: IEEE Double Precision Floating-Point
Representation (64 bits)
1234.56 Æ normalization Æ1.23456 × 103 (scientific
notation) Æ (123456, 3) (fraction, exponent) pair 1 11 52 bits
IEEE Single Precision Floating-Point Representation
(32 bits) Sign bit (1) Exponent (11) Fractional part (52)

1 8 23 bits Range:
-2.2250738585072014 × 10-308 ~
Sign bit (1) Exponent (8) Fractional part (23) 1.7976931348623158 × 10308

Range: -1.75494351 × 10-38 ~ 3.402823466 × 1038 Precision: 16 decimal digits

Precison: 7 decimal digits, 0.9999999 = 0.99999999

- 17 - - 18 -

You might also like