Chapter1 2
Chapter1 2
Representation of Information
in Computers
Contents
2
2.1. Number Systems
• Decimal System
• Base-b System
• Convertion from Decimal to Base-b
• Binary System
• Hexadecimal System
• Octal System
3
Number Categories
• Natural numbers
• Integers
• Rational numbers
• Irrational numbers
4
Decimal System
5
Decimal System (cont’d)
j
d
j0
* 10 j
6
Base-b System
• b digits is used in the representation of numbers.
• Example
1410 = 226 = 1123 = 11102
• If i is an integer written in base - b with digits dj:
i = dn-1dn-2 . . . . d1d0
then i represents the sum:
n 1
Convert from base b
j 0
d j *b j
to base 10
where n is the total number of digits, and dj is the j th digit
from the rightmost position in the decimal number.
• When the base is higher than 10, we need symbols to
represent the digits that correspondent to the decimal values
of 10 and beyond.
7
Example
8
Convert integers from decimal to base b
Remainder Method:
9
Example 1
10
Convert Decimal Fractions to Base-b
11
Example 1
12
Example 2
Binary representation of the decimal fraction 0.1
.1 x 2 = 0.2
The first binary digit to the right of the point is a 0
.2 x 2 = 0.4
The second binary digit to the right of the point is also a 0.
.4 x 2 = 0.8
The third binary digit to the right of the point is also a 0.
.8 x 2 = 1.6
The fourth binary digit to the right of the point is a 1.
.6 x 2 = 1.2
The fifth binary digit to the right of the point is a 1.
The next step to be performed (multiply 2. x 2) is exactly the same
action we had in step 2. We are then bound to repeat steps 2-5, then
return to Step 2 again indefinitely
.1 (decimal) = .00011001100110011 . . .
The repeating pattern is 0011
13
Binary System
14
Hexadecimal System
15
Octal System
16
Data Representation in a Computer-Units of Information
• Basic Principles
• Units of Information
17
Basic Principles
18
Data and Computers
19
Analog and Digital Information
20
Binary Representation
21
Representing Audio Information
22
Representing Colors
23
Three Dimensional Color Space
24
Some TrueColor RGB Values
25
Digitized Images and Graphics
26
Categorization of Data Types in programming
27
Units of information
28
Units of information
29
Representation of Integers
• Unsigned Integers
• Signed Integers
30
Unsigned Integers
31
Range of 8 bit representation
32
Signed Integers
33
Signed Integers (cont’d)
34
Two’s Complement
35
Example
Performing two's complement on the decimal 42 to get -42
36
Two's Complement Arithmetic
50 - 42 = 50 + (-42) = 8
00110010 50
37
Range of 8 bit representation
38
Operations on Integers
39
Addition and Subtraction
• Addition
• Subtraction
40
Binary Addition
0+0=0
0+1=1
1+0=1
1 + 1 = 0, and carry 1 to the next more significant bit
41
Example
42
Binary Subtraction
0-0=0
0 - 1 = 1, and borrow 1 from the next more significant bit
1-0=1
1-1=0
43
Overflow in addition
44
Multiplication and Division
• Multiplication
• Division
45
Binary Multiplication
0x0=0
0x1=0
1x0=0
1 x 1 = 1, and no carry or borrow bits
46
Example
47
Binary Division
48
Logical Operations on Binary Numbers
49
Logical Operations with One or Two Bits
50
Logical Operations with One or Two Integers
• NOT
• AND
• OR
• XOR
51
NOT operation
52
AND operation
53
OR operation
54
XOR Operation
55
Symbol Representation
• Basic Principles
• ASCII Code Table
• Unicode Code Table
56
Basic Principles
57
Character Set
58
ASCII Code Table
59
The Standard ASCII Code Table
60
The extended ASCII characters
61
Limitations of ASCII character set
62
Unicode Code Table
63
Unicode Character Set
64
Some Symbols in the Unicode Character Set
65
Advantages of using Unicode
66