Chapter 6-1
Transforming Data into Information
Outline
• How Computers Represent Data
▪ Number System
▪ Text Codes
▪ Image/Sound
2
How Computers Represent Data
– Number System
• Computer processing is performed by transistors,
which are switches with only two possible states: on
and off.
• If a transistor is assigned a value of 1, it is on. If it
has a value of 0, it is off. A computer’s transistors can
be switched on and off millions of times each second.
• All computer data is converted to a series of binary
numbers – 1 and 0. For example, you see a sentence as
a collection of letters, but the computer sees each
letter as a collection of 1s and 0s.
3
Ten different
symbols in
the decimal
system
Numbers
above 9
use more than
1 digit
Number System Base 10 Base 2
0 0
1 1
• To convert data into strings of
numbers, computers use the binary 2 10
number system. 3 11
• Humans use the decimal system (“deci” 4 100
stands for “ten”). 5 101
• The binary number system works the 6 110
same way as the decimal system, but 7 111
has only two available symbols (0 and 1)
8 1000
rather than ten (0, 1, 2, 3, 4, 5, 6, 7, 8,
and 9). 9 1001
10 1010
5
How Computers Represent Data
- Bits and Bytes
• A single unit of data is called a bit, having a value of 1 or
0.
• Computers work with collections of bits, grouping them
to represent larger pieces of data, such as letters of the
alphabet.
Example:- ‘A’ → 0100 0001
.
• Eight bits make up one byte.
• With one byte, the computer can represent one of 256
different symbols or characters.
1 01 10 1 01 01 1 01
Number System
- Octal Number System
• Number system to the base 8, used in
computing.
• Numbers used - 0, 1, 2, 3, 4, 5, 6, 7.
Number System
- Hexadecimal Number System
• Number system to the base 16, used in
computing.
• Numbers used - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
"A", "B", "C", "D", "E" and "F".
Base Conversion Table
Convert From Any Base To Decimal
• Let’s consider the decimal number 1234
1 2 3 4
Digit Value: (10^3) (10^2) (10^1) (10^0)
1000 100 10 1
1*1000+2*100 + 3*10 + 4*1 = 1234
• Likewise, in a hexadecimal number
… 16^3=4096 16^2=256 16^1= 16 16^0=1
• In a octal number
… 8^3=512 8^2=64 8^1=8 8^0=1
Example : Binary to Decimal
• Binary number 1001 to decimal
1 0 0 1
Digit value (2^3) (2^2) (2^1) (2^0)
8 4 2 1
Decimal Value: 1*8+0*4 + 0*2+1*1=9
Example : Binary to Decimal cnt…
• Binary number 1001.01 to decimal
1 0 0 1 . 0 1
Digit value (2^3) (2^2) (2^1) (2^0) (1/2^1) (1/2^2)
8 4 2 1 0.5 0. 25
Decimal Value: 1*8+0*4 + 0*2+1*1+0*0.5+1*0.25= 9. 25
Examples
1. What is 1111 in Decimal?
2. What is 1101 in Decimal?
3. What is 1.1 in Decimal?
4. What is 10.11 in Decimal?
Example : Octal to Decimal
• Octal number 234 to decimal
2 3 4
Digit value (8^2) (8^1) (8^0)
64 8 1
Decimal Value: 2*64+3*8 + 4*1=156
Example : Octal to Decimal
• Octal number 234.14 to decimal
2 3 4 . 1 4
Digit value (8^2) (8^1) (8^0) (1/8^1) (1/8^2)
64 8 1 0.125 0.015625
Decimal Value: 2*64+3*8 + 4*1+1*0.125+4*0.015625
=156.1875
Example : Hexadecimal to Decimal
• Hexadecimal number 4B3 to decimal
4 B 3
Digit value (16^2) (16^1) (16^0)
256 16 1
Decimal Value: 4*256+11*16 + 3*1= 1203
Example : Hexadecimal to Decimal
• Hexadecimal number 4B3.3 to decimal
4 B 3 . 3
Digit value (16^2) (16^1) (16^0) (1/16^1)
256 16 1 0.0625
Decimal Value: 4*256+11*16 + 3*1+3*0.0625 = 1203.1875
Examples
1. What is 2E6 (Hexadecimal) in Decimal?
2. What is 2.3 (Hexadecimal) in Decimal?
3. What is 24B.A (Hexadecimal) in Decimal?
Convert From Decimal to Any Base
Let’s consider the decimal number 1234
Base = 10
10)1234
10)123 -4
10)12 -3
10)1 - 2 -------------
0 -1
1 2 3 4 (Base 10: Decimal)
Example: Decimal to Binary
• Let’s consider the decimal number 1341
2)1341
2)670 -1
2)335 -0
2)167 -1
2)83 -1
2)41 -1
2)20 -1
2)10 -0
2)5 -0
2)2 - 1 --------------
2)1 - 0 -----------
0 - 1----→ 1 0 1 0 0 1 1 1 1 0 1 (Base 2: Binary)
Example: Decimal to Binary contd…
• Decimal number 1341.3
Integer part = 1 0 1 0 0 1 1 1 1 0 12
Example: Decimal to Binary contd…
Fractional part (Base 2 : Binary)
0.0 1 0 0 1 1 0 …
0.3*2 = 0.6 0 ---
0.6*2 =1.2 1 ------
0.2*2 =0.4 0 --------
0.4*2 =0.8 0 ----------
0.8*2 =1.6 1 -------------
0.6*2 =1.2 1 ----------------
0.2*2 =0.4 0 ----------------------
1341.3 (Dec)= 10100111101.0100110… (Binary)
Example: Decimal to Octal
• Again consider the decimal number 1341
8)1341
8)167 -5
8)20 - 7 --------------
8)2 - 4 ----------
0 - 2 ------
2 4 7 5 (Base 8 : Octal)
Example: Decimal to Hexadecimal
• Again consider the decimal number 1341
16)1341
16)83 - 13 --------------
16)5 - 3 ----------
0 - 5 ------
5 3 D (Base 16 : Hex)
Example: Decimal to Hexadecimal contd…
• Decimal number 3315.3
• Integer part
16)3315
16)207 - 3 --------------
16)12 - 15 ----------
0 - 12 ------
C F 3 (Base 16 : Hex)
Example: Decimal to Hexadecimal cnt…
• Fractional part (Base 16 : Hex)
0.4 C C C …
0.3*16 = 4.8 4 -------
0.8*16 =12.8 12 ----------
0.8*16 =12.8 12 -------------
0.8*16 =12.8 12 ----------------
3315.3 (Dec) = CF3.4CCC… (Hex)
Hexadecimal-Binary Interconversion
Convert to binary form
a) 3D59
b) 27.A3C
28
Hexadecimal-Binary Interconversion
Replace each hexadecimal digit by its 4-bit
representation
29
Binary-Hexadecimal Interconversion
Convert to a hexadecimal number
a) 10110101
b) 110101110001100
c) 100111.101011
30
Representing Negative Numbers
• Three methods for representing negative
numbers are
• Sign-Magnitude
• One’s Complement
• Two’s Complement
Assumption: Representation in Memory
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
8 – BIT Representation
Sign-Magnitude Notation
• As its name implies, a sign-magnitude representation
records the number’s sign and magnitude.
• The most significant bit is 0 for positive numbers and
1 for negative numbers.
• The rest of the bits are set as usual.
Example:- Suppose you are working with 8-bit values
0100 0000 = 64 and 1100 0000 = -64
Sign-Magnitude Notation contd…
Example:-
Find
1) -59
2) -20
3) -25
Sign-Magnitude Notation contd…
Can the "binary addition algorithm" be used
with sign-magnitude representation?
Try adding +16 with -24:
34
One’s Complement Notation
• Positive integers are represented in the same way
as sign-magnitude notation.
• A negative integer is represented by the 1’s
complement of the positive integer in sign-
magnitude notation.
• The one’s complement of a number is obtained by
1. Complementing each one of the bits, i.e., a 1
is replaced by a 0, and a 0 is replaced by a 1.
OR
2. By subtracting each digit by 1.
One’s Complement Notation
Example:-
18 (Base 10) = 0001 0010
-18 (Base 10) = 1's complement of 18 = 1110
1101
One’s Complement Notation
Can the "binary addition algorithm" be used with one’s
complement notation?
Try adding +16 with -24:
One’s Complement Addition
(1) 1- 6 =? (2) 3-3=?
One’s Complement Addition
(1) 1- 6 =? (2) 3-3=?
(1) +1 0001 (2) +3 0011
-6 1001 -3 1100
--- ------- ------
-5 1010 0 1111
Two’s Complement Notation
• The two’s complement representation of positive
integers is the same as in sign-magnitude representation.
• A negative number is represented by the two’s
complement of the positive integer with the same
magnitude.
The two’s complement of a number is obtained by
Method 1
1. Perform the 1’s complement operation.
2. Treating the result as an unsigned binary integer, add 1.
OR
Method 2
1. Starting at the right hand side, rewrite the numbers up to and
including the first 1.
2. For the remainder of the number, change all 0s for 1s and all
1s for 0s.
Two’s Complement contd…
Example
Method 1:
18 = 0001 0010
one’s complement = 1110 1101
+1
two’s complement of 18 = 1110 1110 = -18
Method 2:
18 = 00010010
two’s complement of 18 = 1110 1110 = -18
Two’s Complement contd…
Decimal Two’s Complement
7 0111
6 0110
5 0101
4 0100
3 0011
2 0010
1 0001
0 0000
−1 1111
−2 1110
−3 1101
−4 1100
−5 1011
−6 1010
−7 1001
−8 1000
Two’s Complement contd…
Example:-
Suppose you are working with 8-bit values.
Convert into binary and use two’s complement
method to find
59 - 32
Two’s Complement contd…
What is the decimal representation of this
8-bit two's complement integer: 1001 1111?
43