1 Number System
1 Number System
Data Representation
AS Computer Science
1.1 Data Representation
1.2 Multimedia
1.3 File Compression
1.1 Data Representation
1.1 Data Representation
• 3268 = (3x1000)+(2x100)+(6x10)+(8x1)
3268 = (3x103)+(2x102)+(6x101)+(8x100)
3268 = (3x103)+(2x102)+(6x101)+(8x100)
Analogue data 模拟数据
As humans, we process data that is called analogue data.
Everything we see, hear, feel and smell is a continuous 连续的 stream of
analogue data to our senses.
Binary representation, binary addition, binary shift, One’s compliment, Two’s complement
Binary
• Each digit in a binary number represents a power 幂 of 2,
Value 8 4 2 1
Heading 23 22 21 20
128 64 32 16 8 4 2 1
27 26 25 24 23 22 21 20
Please convert 01100110 (Binary) to denary
representation
Step 2: Sum of the products of digits and value
128 64 32 16 8 4 2 1
27 26 25 24 23 22 21 20
0 1 1 0 0 1 1 0
128 64 32 16 8 4 2 1
Denary -> Binary
Step 2:
Going from left to right, if the value is less than
current number, subtract the value from the number.
Mark that digit as 1.
128 64 32 16 8 4 2 1
1
Denary -> Binary
Step 3: Repeating until the end
171-128 = 43
Check if 43 > 64?
128 64 32 16 8 4 2 1
1 0
Denary -> Binary
Step 3: Repeating until the end
171-128 = 43
Check 43 > 64?
Check 43 > 32?
128 64 32 16 8 4 2 1
1 0 1
Denary -> Binary
Step 3: Repeating until the end
43-32 = 11
Next valid digit is ‘8’
128 64 32 16 8 4 2 1
1 0 1 0 1
Denary -> Binary
Step 3: Repeating until the end
11-8 = 3
Next valid digit is ‘2’
128 64 32 16 8 4 2 1
1 0 1 0 1 0 1
Denary -> Binary
Step 3: Repeating until the end
3 – 2 = 1
Next valid digit is ‘1’
DONE!!
128 64 32 16 8 4 2 1
1 0 1 0 1 0 1 1
Subtraction Summary :
Step 1: write down 8 bits and it’s corresponding denary value
Step 2: Going from left to right, if the value is less than current
number, subtract the value from the number. Mark that digit as 1.
Step 3: Repeating until the end
What is 5 in binary? Modulus method
0011 1011
What is 39 in binary?
Divisor Dividend & Reminder
quotient
39
2
What is 39 in binary?
Divisor Dividend & Reminder
quotient
39
2 19 1
ANS = 100111
2 9 1
2 4 1
2 2 0
2 1 0
2 0 1
Binary Addition
there are four rules that you will need to use:
Rule 1 is 0 + 0 = 0
Rule 2 is 1 + 0 = 1
Rule 3 is 1 + 1 = 10 (this is because 10 in binary is 2)
Rule 4 is 1 + 1 + 1 = 11 (this is because 11 in binary is
3)
Binary Addition
Please perform a binary addition for 0110 and 0001.
Binary Addition
Please perform a binary addition for 0110 and 0011.
0 1 1 0
0 0 1 1
+
Binary Addition
Please perform a binary addition for 0110 and 0011.
0 1 1 0
0 0 1 1
+
1
Binary Addition
Please perform a binary addition for 0110 and 0011.
0 1 1 0
0 0 1 1
+ 1
0 1
Binary Addition
Please perform a binary addition for 0110 and 0011.
0 1 1 0
0 0 1 1
+ 1
0 0 1
Binary Addition
Please perform a binary addition for 0110 and 0011.
0 1 1 0
0 0 1 1
+ 1 1
1 0 0 1
In denary, 6 + 3 = 9
Binary Addition
Please perform a binary addition for
1101 1010 and 1001 0110 for 8 bits integer.
Binary Addition
a binary addition for 1101 1010 and 1001 0110.
1 1 0 1 1 0 1 0
1 0 0 1 0 1 1 0
+ 1 1 1 1
1 0 1 1 1 0 0 0 0
Binary Addition
a binary addition for 1101 1010 and 1001 0110.
1 1 0 1 1 0 1 0
1 0 0 1 0 1 1 0
+ 1 1 1 1
1 0 1 1 1 0 0 0 0
One’s complement:
Each digit in the binary number is inverted (0 to 1 and 1 to 0).
Ex:
0 1 0 1 1 0 1 0 (90)
1 0 1 0 0 1 0 1 (−90).
Binary Subtraction
8 -8
Two’s Compliment
-128 64 32 16 8 4 2 1
1 1 1 1 1 1 1 1
0 0 1 1
0 0 1 1
?
Binary Shift
0 0 1 1
0 0 1 1
?
Ans 0 0 0 1
Binary Shift
A shift to the right === divide by a power of 2, and only retained the
whole number (3/2 = 1)
Binary Shift
5 == 0000 0101
Shift one place to the right (/2)
0000 0010 == 2
Shift two place to the right (/4)
0000 0001 == 1
Shift one place to the left (*2)
0000 1010 == 10
Shift two place to the left (*4)
0001 0100 == 20
Binary Shift
5 == 0101
Shift one place to the right (/2)
0010 -> 2
Shift two place to the right (/4)
0001 -> 1
Shift one place to the left (*2)
1010 -> 10
Shift two place to the left (*4)
0100 -> 4
Measurement of memory 内存 size
Why hexadecimal?
16 1
161 160
E = 14 5
8 4 2 1 8 4 2 1
0 1 1 0 1 1 1 0
8 4 2 1 8 4 2 1
0 1 1 0 1 1 1 0
4+2 = 6 8+4+2=E(14)
8 4 2 1 8 4 2 1
0 1 1 0 1 1 1 0
4+2 = 6 8+4+2=E(14)
ANS = 6E
Step1: Group every 4 bits together
Step2: Convert each group into one hexadecimal digits
Step3: Combine hex digits
Binary -> Hexadecimal
• Note: If there are not enough digits to make a group of 4, add
leading zeros as needed.
Hexadecimal -> Binary
1. Hex -> Denary -> Binary
2. Convert each hex digit into 4 bits (Recommended)
A = 10 2
8 4 2 1 8 4 2 1
Hexadecimal -> Binary
Please convert A2(Hexadecimal) to Binary representation
A = 10 2
8 4 2 1 8 4 2 1
1 0 1 0 0 0 1 0
ANS = 650
Denary to hexadecimal
Please convert 57 (Denary) to Hexadecimal representation
Denary -> Binary -> Hexadecimal
Memory dumps
Hexadecimal is often used when developing new software or when
trying to trace errors in programs.
When the memory contents are output to a printer or monitor, this is
known as a memory dump.
Memory dumps
. 9 4
+ 1 0 0 1 0 1 0 0
1 1 1
1 1 0 0 1 0 1 1
12 11
. 9 4
+ 1 0 0 1 0 1 0 0
1 1 1
1 1 0 0 1 0 1 1
12 11
What happened?