1st Lecture - Number - System, IEEE754
1st Lecture - Number - System, IEEE754
and
Code Conversion
0 +0 = 0 1 1 1 0
0 +1 = 1 1 0 1 1
1 +0 = 1 + 1 1 1 0
1 +1 = 10 1 1 0 0 1
carry
Binary addition: Another example
The initial carry
in is implicitly 0
1 1 0 0 (Carries)
1 1 0 1
+ 1 1 0 0
1 1 0 0 1 (Sum)
(37)10 = (100101)2
(.0625)10 = (.0001)2
• Divide the number and every subsequent quotient by eight and keep
track of the remainder.
Decimal-to-Hexadecimal Conversion
• Repeated division of a decimal number by 16 will
produce the equivalent hexadecimal number, formed
by the remainders of the divisions. The first remainder
produced is the least significant digit (LSD). Each
successive division by 16 yields a remainder that
becomes a digit in the equivalent hexadecimal number.
When a quotient has a fractional part, the fractional
part is multiplied by the divisor to get the remainder.
Decimal-to-Hexadecimal Conversion
• Convert the decimal number 650 to hexadecimal by repeated division by
16.
• 650 = 40.625 0.625 x 16 = 10 = A (LSD)
• 16
• 40 = 2.5 0.5 x 16 = 8 = 8
• 16
• 2 = 0.125 0.125 x 16 = 2 = 2 (MSD)
• 16
• The hexadecimal number is 28A
Decimal-to-Hexadecimal Conversion
0 0000 8 1000
1 0001 9 1001
2 0010 A 1010
3 0011 B 1011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111
Hexadecimal-to-Binary Conversion
• Translate every hexadecimal digit into its 4-
bit binary equivalent.
• Examples:
(3A5)16 = (0011 1010 0101)2
(12.3D)16 = (0001 0010 . 0011 1101)2
(1.8)16 = (0001 . 1000)2
Hexadecimal-to-Decimal Conversion
• One way to find the decimal equivalent of a
hexadecimal number is to first convert the
hexadecimal number to binary and then convert
from binary to decimal.
• Example:
• (1C)16 = (0001 1100)2 = 24 + 2³ + 2² = 16 + 8 + 4
= 28
Hexadecimal-to-Octal Conversion
• Use binary as an intermediary.
Octal Numbers
• Like the hexadecimal system, the octal system provides a convenient way to
express binary numbers and codes.
• However, it is used less frequently than hexadecimal in conjunction with
computers and microprocessors to express binary quantities for input and
output purposes.
• The octal system is composed of eight digits, which are:
• 0, 1, 2, 3, 4, 5, 6, 7
• To count above 7, begin another column and start over:
• 10, 11, 12, 13, 14, 15, 16, 17, 20, 21 and so on.
• Counting in octal is similar to counting in decimal, except that the digits 8 and 9
are not used.
Octal-to-Decimal Conversion
• Since the octal number system has a base of eight, each successive digit
position is an increasing power of eight, beginning in the right-most
column with 80. The evaluation
• Of an octal number in terms of its decimal equivalent is accomplished by
multiplying each digit by its weight and summing the products.
• Let’s convert octal number 2374 in decimal number.
• Weight 8³ 8² 81 80
• Octal number 2 3 7 4
• 2374 = (2 x 8³) + (3 x 8²) + (7 x 81) + (4 x 80)=1276
Octal-to-Binary Conversion
• Because each octal digit can be represented by a 3-bit binary number, it is
very easy to convert from octal to binary..
• Octal/Binary Conversion
• Octal Digit 0 1 2 3 4 5 6 7
• Binary 000 001 010 011 100 101 110 111
Let’s convert the octal numbers 25 and 140.
2 5 1 4 0
010 101 001 100 000
Octal-to-Hexadecimal Conversion
• Use binary as an intermediary.
Unsigned Binary Numbers
• An n-bit binary number
B = bn-1bn-2 …. b2b1b0
• 2n distinct combinations are possible, 0 to 2 n-1.
• For example, for n = 3, there are 8 distinct combinations.
– 000, 001, 010, 011, 100, 101, 110, 111
• Range of numbers that can be represented
n=8 0 to 28-1 (255)
n=16 0 to 216-1 (65535)
n=32 0 to 232-1 (4294967295)
Signed Integer Representation
• Many of the numerical data items that are used in a program
are signed (positive or negative).
– Question:: How to represent sign?
Sign Magnitude
Representation and ZERO
• Range of numbers that can be represented:
Maximum :: + (2n-1 – 1)
Minimum :: (2n-1 – 1)
• A problem:
Two different representations of zero.
+0 0 000….0
-0 1 000….0
One’s Complement Representation
• Basic idea:
– Positive numbers are represented exactly as in sign-
magnitude form.
– Negative numbers are represented in 1’s complement
form.
IEEE 754 numbers are divided into two representation based on the three
components (Sign, Exponent and Mantissa):
o Single precision (32-bit)
o Double precision (64-bit)
IEEE 754 has 3 basic components: