Number System and Data Representation
Number System and Data Representation
1. Number System
2. Data Representation 3. Integer Representation
1. Number Systems
Fundamental to understand how computers work is understanding the number system that computer use to store data and communicate with each other. Number system been used to understand computer:
Base 10 (decimal)
E.g.: 394510 / 3945d
Base 2 (binary)
E.g.: 101010112 / 10101011b
Base 16 (hexadecimal)
E.g.: 0A3E16 / 0A3Eh
3
The decimal system is said to have a base or radix of 10. Each digit in the number is multiplied by 10 raised to a power corresponding to that digits position:
4728 = (4 x 103) + (7 x 102) + (2 x 101) + (8 x 100)
4
(1 x 20) = 43d
0001 = 1
0010 = 2 0011 = 3
1001 = 9
1010 = A 1011 = B
0100 = 4
0101 = 5 0110 = 6
1100 = C
1101 = D 1110 = E
0111 = 7
1111 = F
7
Each digits in a hexadecimal number also have a value depending on its position:
2C16= (2 x 161)+ (C x 160) = (2 x 161)+ (12 x 160) = 4410 The reason for using hexadecimal notation are because it is more compact than binary notation and it is extremely easy to convert between binary and hexadecimal.
3
4 5 6 7 8 9 10 11 12 13 14 15
0011
0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
3
4 5 6 7 8 9 A B C D E F
10
11
= 262310
12
Decimal can be converted in to a binary systems with the Remainder Method Example: Convert 26d to base 2 26/2 = 13 0 Least significant bit 13/2 = 6 1
6/2 = 3/2 = 1/2 = => 26d = 11010b
13
3 1 0
How about floating point number? E.g.: Convert 0.875d into base 2 number.
0.875 x 2 = 1.75 0.75 x 2 = 1.5 0.5 0 x 2 = 1.0 x2 = 0 1 1 1 0
15
To convert a hex number to binary, we need only express each hex digit in binary E.g.: Convert DE116 to binary D E 1 = 1101 1110 0001 = 110111100001b To go from binary to hex, just reverse this process
100100012 = 1001 0001 = 9116
16
1. Number System
2. Data Representation
3. Integer Representation
17
2. Data Representation
A common form of data are letters of the alphabet (A to Z), numerals (0 to 9), some symbols (@, &, *) and certain control character (Ctrl,Shift). This types of data is convenient for human being but all of the data in digital computer represented in binary form. Some coding systems are used to represent these data into the binary form. (Characters are represented by a sequence of bits.)
18
19
0000 0100 0000 0101 0000 0000 0000 0000 0000 0000 0000 0110 0111 1000 1001 1010 1011 1100
0000 1101 0000 1110 0000 1111 0001 0000 0001 0001 0001 0010 0001 0011 0001 0100
0001 0101 0001 0110 0001 0001 0001 0001 0001 0001 0111 1000 1001 1010 1011 1100
21 22 23 24 25 26 27 28 29 30 31 127
15 16 17 18 19 1A 1B 1C 1D 1E 1F 7F
Codes 33 to 126 are called the printable characters, which represent letters, digits, punctuation marks, and a few miscellaneous symbols.
22
% & ' ( )
0011 0101 0011 0110 0011 0111 0011 1000 0011 1001 0011 1010
* + , -
0011 1011 0011 1100 0011 1101 0011 1110 0011 1111
23
@ A B C D E F G H I J K L
0101 0000 0101 0001 0101 0010 0101 0011 0101 0100 0101 0101 0101 0110 0101 0111 0101 1000 0101 1001 0101 1010 0101 1011 0101 1100 0101 1101
M N
0101 1110 0101 1111
24
25
3. Integer Representation
28
29
30
31
Largest number is +127 and smallest number is 127 Problems:Two representations for zero:
+0 -0 = = 00000000b 10000000b
32
One representation for zero: 0000000b Largest number is +127 and smallest number is -128
34
Signed Magnitude
Ones Complement Twos Complement
2
2 2
n-1-1
-(2
-(2 -(2
n-1-1)
n-1-1
n-1-1)
n-1-1
n-1)
35
36