Data Representation
Data Representation
1
+Example 1: (from decimal to binary) +Example 3: (from decimal to Hexadecimal)
• (37.375)10 • (423.78)10
2
• Represent each digit in Octal by 3 +Example 1: (from binary to Hexadecimal)
bits to find the equivalent binary • (1110100110.011)2
number. = 0011 1010 0110 . 0110
Hexadecimal Octal
= 3 A 6 . 6
8 4 2 1 4 2 1
= (3A6.6)16
3
+Example 2: (from Octal to Hexadecimal) B) The 2’s complement:
• (71)8 - Method #1 -
• Using ther rule : 2n -N
-Using decimal: where: n is number of bits , N is digit
(71)8 = 7 x 81 + 1 x 80 = 56 + 1
(71)8 = (57)10 +Example:
16 57 remainder If n= 4bits , The 2’s complement of
16 3 9 (0010)2 is .......
0 3 2n -N = 24 – 2 = 14
(57)10 = (39)16 2 14 remainder
So (71)8 = (39)16 2 7 0
2 3 1
-Using binary: 2 1 1
( 7 1 )8 0 1
= (111 001)2 (14)10 = (1110)2
= (0011 1001)2 so the 2’s complement of (0010)2 is (1110)2
=( 3 9 )16
= (39)16 - Method #2 -
• After the first 1 convert all 0 to 1
and all 1 to 0 (from right to left )
3] Negative Number
Representation : - Method #3 -
• There are two formats for • Convert all 0 to 1 and all 1 to 0 then
representing negative numbers in add one to the result
base-2 system:
1. Sign-magnitude - Weights -
2. 2’s complement • Weights of 2’s complement (3 bit)
are : -4 2 1
A) Sign-magnitude: • Weights of 2’s complement (4 bit)
• This type uses one bit for the sign are : -8 4 2 1
(0 = positive, 1 = negative) and the • Weights of 2’s complement (n bit)
remaining bits represent the are : -2n-1 2n-2 2n-3 … 21 20
magnitude of the number.
0 1
+ve number -ve number
example: example:
(0001)2 = +1 (1001)2 = -1
• Note:
(Sign mag.) = -5
1. (1101)2
(Unsigned mag.) = 13
5
+Example 3: calculate ( 5 - 9 ) in binary 5] Notes:
(5)10 = (101)2 = (00101)2 • How many values can be
(9)10 = (1001)2 = (01001)2 its 2’s comp.
represented in n bits ??
is (10111)2
If n = 5 …
1 1 1 The rule is ( 2n )
0 0 1 0 1 So in 5 bits we can represent 25 = 32
+
1 0 1 1 1 values ( from 00000 to 11111 ) in
1 1 1 00 decimal is ( from 0 to 31 ).
no extra bit appeared
the result is -ve. • What’s the Largest and Smallest
number that can represented in n
so (00101)2 - (01001)2 = (11100)2 and it is a digits ?
negative number If n = 5 …
The rule of the largest value is ( 2n-1 )
- The Decimal value of a negative binary So in 5 bits the largest value is 25-1 =
number - (11111)2 in decimal (31)10
• To know the value of the negative
And always the Smallest value is 0
number (11100)2 use one of the following
methods : So the smallest value is (00000)2 in
decimal (0)10
First method: get the 2’s complement of
that negative number to know its positive • How many bits needed to
value then add negative to that positive represent x decimal value ?
value. If value (x) = 17 …
(11100)2 its 2’s complement is (00100)2
The rule is ( 2n-1 -1 < x < 2n -1 )
(00100)2 = 4
(11100)2 = -4 24 -1 < 17 < 25 -1
So the n bits can represent 17 is 5 bits
Second method: use Weights of 2’s where (17)10 = (10001)2
complement.
(11100)2 = (1 x -16) + (1 x 8) + (1 x 4) = -4