Chapter 2
Data Representation and The
Number System
Lesson objectives
At the end of this chapter students
able to
Define Numbering system
Practice Number system conversion
Identify Units of data representation
Identify Coding methods
Exercise floating point representation
Types Of Numbers
Natural Numbers
The number 0 and any number obtained by
repeatedly adding a count of 1 to 0
Negative Numbers
A value less than 0
Integer
A natural number, the negative of a natural number,
and 0.
So an integer number system is a system for
‘counting’ things in a simple systematic way
Exponent Review
An exponent (power) tells you how many
times to multiply the base by itself:
21 = 2
22 = 2 x 2 =4
23 = 2 x 2 x 2 = 8
20 = 1 (ANY number raised to power 0
is 1)
1 / x2 = x -2
numbering system
The general idea behind positional
numbering systems is that a
numeric value is represented
through increasing powers of a radix
(or base). This is often referred to as
a weighted numbering system
because each position is weighted
by a power of the radix
Decimal Numbering
System
How is a positive integer represented in decimal?
Let’s analyze the decimal number 375:
375 = (3 x 100) + (7 x 10) + (5 x 1)
= (3 x 102) + (7 x 101) + (5 x 100)
Position weights 102 101 100
Number digits 3 7 5
5 x100 = 5 +
7 x101 = 70 +
3 x 102 = 300
375
Decimal System Principles
A decimal number is a sequence of digits
Decimal digits must be in the set: {0, 1,
2, 3, 4, 5, 6, 7, 8, 9} (Base 10)
Each digit contributes to the value the number
represents
The value contributed by a digit equals the product of
the digit times the weight of the position of the digit in
the number
Decimal System Principles
Position weights are powers of 10
The weight of the rightmost (least significant digit)
is 100 (i.e.1)
The weight of any position is 10x, where x is the
number of positions to the right of the least
significant digit
Position weights 104 103 102 101 100
digits 3 7 5
Bits
In a computer, information is stored using digital
signals that translate to binary numbers
A single binary digit (0 or 1) is called a bit
A single bit can represent two possible states,
on (1) or off (0)
Combinations of bits are used to store values
Data Representation
Data representation means encoding data into bits
Typically, multiple bits are used to represent the
‘code’ of each value being represented
Values being represented may be characters, numbers,
images, audio signals, and video signals.
Although a different scheme is used to encode each type
of data, in the end the code is always a string of zeros
and ones
Decimal to Binary
So in a computer, the only possible digits we can use to
encode data are {0,1}
The numbering system that uses this set of digits is
the base 2 system (also called the Binary Numbering
System)
We can apply all the principles of the base 10 system to
the base 2 system
Position weights 24 23 22 21 20
digits 1 0 1 1
Binary Numbering
System
How is a positive integer represented in binary?
Let’s analyze the binary number 110:
110 = (1 x 22) + (1 x 21) + (0 x 20)
= (1 x 4) + (1 x 2) + (0 x 1)
Position weights 22 21 20
Number digits 1 1 0
0 x20 = 0 +
1 x21 = 2 +
1 x 22 = 4
6
So a count of SIX is represented in binary as 110
Binary to Decimal
Conversion
To convert a base 2 (binary) number to
base 10 (decimal):
Add all the values (positional weights)
where a one digit occurs
Positions where a zero digit occurs do
NOT add to the value, and can be
ignored
Binary to Decimal
Conversion
Example: Convert binary 100101 to decimal
(written 1 0 0 1 0 12 ) =
1*20 + 1+
0*21 +
4+
1*22 +
0*23 +
0*24 + 32
1*25
3710
Binary to Decimal
Conversion
Example #2: 101112
positional powers of 2: 2 4 2 3 22 21 20
decimal positional value: 16 8 4 2 1
binary number: 1 0 1 1 1
16 + 4 + 2 + 1 = 2310
Binary to Decimal
Conversion
Example #3: 1100102
positional powers of 2: 2 5 2 4 2 3 2 2 21 20
decimal positional value: 32 16 8 4
2 1
binary number: 1 1 0 0 1 0
32 + 16 + 2 =
5010
Decimal to Binary
Conversion
The Division Method:
1) Start with your number (call it N) in base 10
2) Divide N by 2 and record the remainder
3) If (quotient = 0) then stop
else make the quotient your new N, and go back to step 2
The remainders comprise your answer, starting with the last
remainder as your first (leftmost) digit.
In other words, divide the decimal number by 2 until you reach
zero, and then collect the remainders in reverse.
Decimal to Binary
Conversion
Using the Division Method:
Divide decimal number by 2 until you reach zero, and then collect the remainders
in reverse.
Example 1: 2210 = 101102
2 ) 22 Rem:
2 ) 11 0
2 ) 5 1
2 ) 2 1
2 ) 1 0
0 1
Decimal to Binary
Conversion
Using the Division Method
Example 2: 5610 = 1110002
2 ) 56 Rem:
2 ) 28 0
2 ) 14 0
2 ) 7 0
2 ) 3 1
2 ) 1 1
0 1
Decimal to Binary
Conversion
The Subtraction Method:
Subtract out largest power of 2 possible
(without going below zero), repeating until you
reach 0.
Place a 1 in each position where you
COULD subtract the value
Place a 0 in each position that you could
NOT subtract out the value without going
below zero.
Decimal to Binary
Conversion
Example 1: 2110
- 16 21 26 2 5 24 23 22 21
20 5 1
0 1
- 4 64 32 16 8 4 02 1
11
- 1 Answer: 2110 = 101012
0
Decimal to Binary
Conversion
Example 2: 5610
56 26 | 25 24 23 22 21 20
- 32 64| 32 16 8 4 2 1
24 |1 1 1 0 0 0
- 16
8
- 8 Answer: 5610 = 1110002
0
Octal Numbering System
Base: 8
Digits: 0, 1, 2, 3, 4, 5, 6, 7
Octal number: 3578
= (3 x 82 ) + (5 x 81) + (7 x 80)
To convert to base 10, beginning with the
rightmost digit, multiply each nth digit by
8(n-1), and add all of the results together.
Octal to Decimal
Conversion
Example 1: 3578
positional powers of 8: 82 81 80
decimal positional value: 64 8 1
Octal number: 3 5 7
(3 x 64) + (5 x 8) + (7 x 1)
= 192 + 40 + 7 = 23910
Octal to Decimal
Conversion
Example 2: 12468
positional powers of 8: 83 82 81 80
decimal positional value: 512 64 8 1
Octal number: 1 2 4 6
(1 x 512) + (2 x 64) + (4 x 8) + (6 x 1)
= 512 + 128 + 32 + 6 = 67810
Decimal to Octal
Conversion
The Division Method:
1) Start with your number (call it N) in base 10
2) Divide N by 8 and record the remainder
3) If (quotient = 0) then stop
else make the quotient your new N, and go back to step 2
The remainders comprise your answer, starting with the last
remainder as your first (leftmost) digit.
In other words, divide the decimal number by 8 until you reach
zero, and then collect the remainders in reverse.
Decimal to Octal
Conversion
Using the Division Method:
Example 1: 21410 =3268
8 ) 214 Rem:
8 ) 26 6
8) 3 2
0 3
Decimal to Octal
Conversion
Example 2: 433010 =
10352 8
8 ) 4330 Rem:
8 ) 541 2
8 ) 67 5
8 ) 8 3
8 ) 1 0
0 1
Decimal to Octal
Conversion
The Subtraction Method:
Subtract out multiples of the largest power
of 8 possible (without going below zero)
each time until you reach 0.
Place the multiple value in each position
where you COULD subtract the value.
Place a 0 in each position that you could
NOT subtract out the value without
going below zero.
Decimal to Octal
Conversion
Example 1: 31510
315 82 81 80
- 256 (4 x 64) 64 8 1
4 7 3
59
- 56 (7 x 8)
3
Answer: 31510 = 4738
- 3 (3 x 1)
Decimal to Octal
Conversion
Example 2: 201810
2018 84 8 3 82 81 80
-1536 (3 x 512) 4096 512 64 8 1
482 3 7 4 2
- 448 (7 x 64)
34
- 32 (4 x 8)
2
- 2 (2 x 1) Answer: 201810 = 37428
0
Hexadecimal (Hex)
Numbering System
Base: 16
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D,
E, F
Hexadecimal number: 1F416
= (1 x 162 ) + (F x 161) + (4 x 160)
Hexadecimal (Hex)
Extra Digits
Decimal Value Hexadecimal Digit
10 A
11 B
12 C
13 D
14 E
15 F
Hex to Decimal
Conversion
To convert to base 10:
Begin with the rightmost digit
Multiply each nth digit by 16(n-1)
Add all of the results together
Hex to Decimal
Conversion
Example 1: 1F416
positional powers of 16: 163 162 161 160
decimal positional value: 4096 256 16 1
Hexadecimal number: 1 F 4
(1 x 256) + (F x 16) + (4 x 1)
= (1 x 256) + (15 x 16) + (4 x 1)
= 256 + 240 + 4 = 500
Hex to Decimal
Conversion
Example 2: 25AC16
positional powers of 16: 163 162 161 160
decimal positional value: 4096 256 16 1
Hexadecimal number: 2 5 A C
(2 x 4096) + (5 x 256) + (A x 16) + (C x 1)
= (2 x 4096) + (5 x 256) + (10 x 16) + (12 x 1)
= 8192 + 1280 + 160 + 12 = 964410
Decimal to Hex
Conversion
The Division Method:
1) Start with your number (call it N) in base 10
2) Divide N by 16 and record the remainder
3) If (quotient = 0) then stop
else make the quotient your new N, and go back to step 2
The remainders comprise your answer, starting with the last
remainder as your first (leftmost) digit.
In other words, divide the decimal number by 16 until you
reach zero, and then collect the remainders in reverse.
Decimal to Hex
Conversion
Using The Division Method:
Example 1: 12610 7E
=16
16) 126 Rem:
16) 7 14=E
0 7
Decimal to Hex
Conversion
Example 2: 60310 =25B16
16) 603 Rem:
16) 37 11=B
16) 2 5
0 2
Binary to Octal Conversion
The maximum value represented in 3 bit
is: 23 – 1 = 7
So using 3 bits we can represent values
from 0 to 7
which are the digits of the
Octal numbering system.
Thus, three binary digits can be converted
to one octal digit.
Binary to Octal Conversion
Three-bit Group Decimal Digit Octal Digit
000 0 0
001 1 1
010 2 2
011 3 3
100 4 4
101 5 5
110 6 6
111 7 7
Octal to Binary Conversion
Ex : Convert 7428 to binary
Convert each octal digit to 3 bits:
7 = 111
4 = 100
2 = 010
111 100 010
7428 = 1111000102
Binary to Octal Conversion
Ex : Convert 101001102 to octal
Starting at the right end, split into groups of 3:
10 100 110
110 = 6
100 = 4
010 = 2 (pad empty digits with 0)
101001102 = 2468
Binary to Hex Conversion
The maximum value represented in 4 bit is:
24 – 1 = 15
So using 4 bits we can represent values
from 0 to 15
which are the digits of the Hexadecimal
numbering system.
Thus, four binary digits can be converted to
one hexadecimal digit.
Binary to Hex
Conversion
Four-bit Group Decimal Digit Hexadecimal Digit
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F
Binary to Hex Conversion
Ex : Convert 1101001102 to hex
Starting at the right end, split into groups of 4:
1 1010 0110
0110 = 6
1010 = A
0001 = 1 (pad empty digits with 0)
1101001102 = 1A616
Hex to Binary Conversion
Ex : Convert 3D916 to binary
Convert each hex digit to 4 bits:
3 = 0011
D = 1101
9 = 1001
0011 1101 1001
3D916 = 11110110012 (can remove leading
zeros)
Conversion between
Binary and Hex - Try It
Yourself
Convert the following numbers:
10101111012 to Hex
82F16 to Binary
(Answers on NEXT slide)
Answers
10101111012 10 1011
1101 = 2BD16
82F16 = 1000 0010 1111
1000001011112
Octal to Hex Conversion
To convert between the Octal and
Hexadecimal numbering systems
Convert from one system to binary first
Then convert from binary to the new
numbering system
Hex to Octal Conversion
Ex : Convert E8A16 to octal
First convert the hex to binary:
1110 1000 10102
111 010 001 010 and re-group by 3 bits
(starting on the right)
Then convert the binary to octal:
7 2 1 2
So E8A16 = 72128
Octal to Hex Conversion
Ex : Convert 7528 to hex
First convert the octal to binary:
111 101 0102
re-group by 4 bits
0001 1110 1010 (add leading zeros)
Then convert the binary to hex:
1 E A
So 7528 = 1EA16
Binary Subtraction
Two n-bit values A B A-B
subtract individual0bits 0 0
0 1 1(borrow)
Propagate borrow
1 0 1
1 1 0
11101 10111
E.g.,
-11001
00100 - 10001
00110
3-
Unsigned Representation
Represents positive integers.
Unsigned representation of 157:
7 6 5 4 3 2 1 0
position
Bit pattern 1 0 0 1 1 1 0 1
contribution 27
24 23 22 20
Addition is simple:
1 0 0 1 + 0 1 0 1 = 1 1 1 0.
3-
Advantages and disadvantages of
unsigned notation
Advantages:
One representation of zero
Simple addition
Disadvantages
Negative numbers can not be
represented.
The need of different notation to
represent negative numbers.
3-
Representation of negative
numbers
Is a representation of negative numbers
possible?
Unfortunately:
you can not just stick a negative sign in
front of a binary number. (it does not work
like that)
There are three methods used to
represent negative numbers.
Signed magnitude notation
Excess notation
Two’s complement notation
3-
Signed Magnitude
Representation
In signed magnitude
the left-most bit represents the
sign of the integer.
0 for positive numbers.
1 for negative numbers.
The remaining bits represent to
magnitude of the numbers.
3-
Example
Suppose 10011101 is a signed
magnitude representation.
The sign bit is 1, then the number
represented is negative
position 7 6 5 4 3 2 1 0
Bit pattern 1 0 0 1 1 1 0 1
contribution 24 23 22 20
-
The magnitude is 0011101 with a value
24+23+22+20= 29
Then the number represented by
10011101 is –29.
3-
Signed-Summary
In signed magnitude notation,
The most significant bit is used to
represent the sign.
1 represents negative numbers
0 represents positive numbers.
The unsigned value of the
remaining bits represent The
magnitude.
Advantages:
Represents positive and negative
numbers
Disadvantages:
two representations of zero, 3-
Fractions Base Conversion
0.828125
2
*
0.110101
1.656250 *
The 1 is saved as 2
result then dropped 1.312500 *
and the process 2
repeated 0.625000 *
2
1.250000 *
2
0.500000 *
2
1.000000
Alphanumeric Data
Three standards for representing letters
(alpha) and numbers
ASCII – American Standard Code for
Information Interchange
EBCDIC – Extended Binary-Coded
Decimal Interchange Code (not used
anymore, used to be used in IBM
mainframes)
Unicode
3-
Codes and Characters
Representing text strings, such as
“Hello, world”, in a computer
Each character is coded as a byte
( = 8 bits)
Most common coding system is
ASCII
ASCII = American National Standard
Code for Information Interchange
3-
Most significant bit
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Least significant bit 3-
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
i.e. ‘a’ = 11000012 = 9710
=6116
3-
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
95 Graphic codes
3-
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
33 Control codes
3-
“Hello, world” Example
Binary Hexadecimal Decimal
H = 01001000= 48 = 72
e = 01100101= 65 = 101
l = 01101100= 6C = 108
l = 01101100= 6C = 108
o = 01101111= 6F = 111
, = 00101100= 2C = 44
= 00100000= 20 = 32
w = 01110111= 77 = 119
o = 01101111= 6F = 111
r = 01110010= 72 = 114
l = 01101100= 6C = 108
d = 01100100= 64 = 100
Note: 12 characters – requires 12 bytes
Each character requires 1 byte 3-
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Numeric codes
3-
“4+15” Example
Binary Hexadecimal Decimal
4 = 00110100= 34 = 52
+ = 00101011= 2B = 43
l = 00110001= 31 = 49
5 = 00110101= 35 = 53
“4+15” is represented as
“00110100 00101011 00110001 00110101”
or “34162B1631163516”
3-
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Punctuation, etc.
3-
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
3-
Thank U!!!
END
3-