0% found this document useful (0 votes)
50 views

1st Lecture - Number - System, IEEE754

The document discusses various number systems including binary, decimal, octal, and hexadecimal. It provides examples of how to convert between these different number systems. Conversions include binary to decimal and vice versa, binary to octal and hexadecimal and vice versa, decimal to binary, octal, and hexadecimal and vice versa. The key aspects of each number system like the radix/base and the place value of each digit are also explained.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

1st Lecture - Number - System, IEEE754

The document discusses various number systems including binary, decimal, octal, and hexadecimal. It provides examples of how to convert between these different number systems. Conversions include binary to decimal and vice versa, binary to octal and hexadecimal and vice versa, decimal to binary, octal, and hexadecimal and vice versa. The key aspects of each number system like the radix/base and the place value of each digit are also explained.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 51

Number System

and
Code Conversion

Dr. Manju Khurana


Assistant Professor, CSED
TIET, Patiala
[email protected]
Number System :: The Basics
Number System :: The Basics
• We are accustomed to using the so-called decimal
number system.
– Ten digits :: 0,1,2,3,4,5,6,7,8,9
– Every digit position has a weight which is a power of 10.
– Base or radix is 10.
• Example:
234 = 2 x 102 + 3 x 101 + 4 x 100
250.67 = 2 x 102 + 5 x 101 + 0 x 100 + 6 x 10-1 + 7 x 10-2
Binary Number System
• Two digits:
– 0 and 1.
– Every digit position has a weight which is a power of 2.
– Base or radix is 2.
• Example:
110 = 1 x 22 + 1 x 21 + 0 x 20
101.01 = 1 x 22 + 0 x 21 + 1 x 20 + 0 x 2-1 + 1 x 2-2
Counting with Binary Numbers
0
1
10
11
100
101
110
111
1000
.
Multiplication and Division with base
 Multiplication with 10 (decimal system)
435 x 10 = 4350
Left Shift and add
zero at right end
 Multiplication with 10 (=2 ) (binary system)
1101 x 10 = 11010
Right shift and drop
 Division by 10 (decimal system) right most digit or
435 / 10 = 43.5 shift after decimal
point
 Division by 10 (=2) (binary system)
1101 / 10 = 110.1
Adding two bits
Carries

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)

most significant least significant


bit (MSB) bit (LSB)
Binary-to-Decimal Conversion
• Each digit position of a binary number has a
weight.
– Some power of 2.
• A binary number:
B = bn-1 bn-2 …..b1 b0 . b-1 b-2 ….. b-m
Corresponding
n-1 value in decimal:
D =i =-m bi 2i
Examples
1. 101011  1x25 + 0x24 + 1x23 + 0x22 + 1x21 + 1x20
= 43
(101011)2 = (43)10

2. .0101  0x2-1 + 1x2-2 + 0x2-3 + 1x2-4


= .3125
(.0101)2 = (.3125)10

3. 101.11  1x22 + 0x21 + 1x20 + 1x2-1 + 1x2-2


5.75
(101.11)2 = (5.75)10
Binary-to-Octal Conversion
• Conversion of a binary number to an octal number is the reverse of the
octal-to-binary conversion.
• Let’s convert the following binary numbers to octal:
• 110101 101111001
• 6 5 = 65 5 7 1 = 571
Binary-to-Octal Conversion
• Group bits into sets of threes, starting from the RHS.
• Convert each set to octal digits.
Binary-to-Hexadecimal Conversion
• For the integer part,
– Scan the binary number from right to left.
– Translate each group of four bits into the corresponding hexadecimal
digit.
• Add leading zeros if necessary.
• For the fractional part,
– Scan the binary number from left to right.
– Translate each group of four bits into the corresponding hexadecimal
digit.
• Add trailing zeros if necessary.
Example
1. (1011 0100 0011)2 = (B43)16

2. (10 1010 0001)2 = (2A1)16

3. (.1000 010)2 = (.84)16

4. (101 . 0101 111)2 = (5.5E)16


Binary-to-Hexadecimal Conversion
• Group bits into sets of fours, starting from the RHS.
• Convert each set to hexadecimal digits.
Decimal-to-Binary Conversion

• Consider the integer and fractional parts separately.


• For the integer part,
– Repeatedly divide the given number by 2, and go on
accumulating the remainders, until the number becomes
zero.
– Arrange the remainders in reverse order.
• For the fractional part,
– Repeatedly multiply the given fraction by 2.
• Accumulate the integer part (0 or 1).
• If the integer part is 1, chop it off.
– Arrange the integer parts in the order they are obtained.
Example 1 :: 239
2 239
2 119 --- 1
3 59 --- 1
2 29 --- 1
(239)10 = (11101111)2
4 14 --- 1
2 7 --- 0
5 3 --- 1
2 1 --- 1
2 0 --- 1
Example 2 :: 64
2 64
2 32 --- 0
3 16 --- 0
2 8 --- 0
(64)10 = (1000000)2
4 4 --- 0
2 2 --- 0
5 1 --- 0
2 0 --- 1
Example 3 :: .634
.634 x 2 = 1.268
.268 x 2 = 0.536
.536 x 2 = 1.072 (.634)10 = (.10100……)2
.072 x 2 = 0.144
.144 x 2 = 0.288
:
:
Example 4 :: 37.0625

(37)10 = (100101)2
(.0625)10 = (.0001)2

(37.0625)10 = (100101 . 0001)2


Decimal-to-Octal Conversion
• A method of converting a decimal number to an octal number is the repeated division-by-8
method, which is similar to the method used in the conversion of decimal numbers to binary
or to hexadecimal.
• Let’s convert the decimal number 359 to octal. Each successive division by 8 yields a
remainder that becomes a digit in the equivalent octal number. The first remainder generated
is the least significant digit (LSD).
• 359 = 44.875 0.875 x 8 = 7 (LSD)
• 8
• 44 = 5.5 0.5 x 8 = 4
• 8
• 5 = 0.625 0.625 x 8 = 5 (MSD)
• 8
• The number is 547.
Decimal-to-Octal Conversion

• 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

• Divide the number and every subsequent quotient by sixteen and


keep track of the remainder.
Hexadecimal Number System
• A compact way of representing binary numbers.

• 16 different symbols (radix = 16).

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?

• Three possible approaches:


– Sign-magnitude representation
– One’s complement representation
– Two’s complement representation
Sign-magnitude Representation
• For an n-bit number representation
– The most significant bit (MSB) indicates sign
0  positive
1  negative
– The remaining n-1 bits represent magnitude.
bn-1 bn-2 b1 b0

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.

• How to compute the 1’s complement of a number?


– Complement every bit of the number (10 and 01).
– MSB will indicate the sign of the number.
0  positive
1  negative
Example :: n=4
0000  +0 1000  -7
0001  +1 1001  -6
0010  +2
1010  -5
0011  +3
0100  +4 1011  -4
0101  +5 1100  -3
0110  +6 1101  -2
0111  +7 1110  -1
To find the representation of -4, first note
1111 that-0
+4 = 0100
-4 = 1’s complement of 0100 = 1011
One’s Complement Representation
• 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 111….1
• Advantage of 1’s complement representation
– Subtraction can be done using addition.
– Leads to substantial saving in circuitry.
Two’s Complement Representation
• Basic idea:
– Positive numbers are represented exactly as in sign-
magnitude form.
– Negative numbers are represented in 2’s complement form.

• How to compute the 2’s complement of a number?


– Complement every bit of the number (10 and 01), and then
add one to the resulting number.
– MSB will indicate the sign of the number.
0  positive
1  negative
Example :: n=4
0000  +0 1000  -8
0001  +1 1001  -7
0010  +2
1010  -6
0011  +3
0100  +4 1011  -5
0101  +5 1100  -4
0110  +6 1101  -3
0111  +7 1110  -2
To find the representation of, say, -4, first note that
1111  -1
+4 = 0100
-4 = 2’s complement of 0100 = 1011+1 = 1100
IEEE Standard 754 Floating Point Numbers
The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical
standard for floating-point computation which was established in 1985 by
the Institute of Electrical and Electronics Engineers (IEEE).

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:

1. The Sign of Mantissa –


This is as simple as the name. 0 represents a positive number while 1
represents a negative number.
2. The Biased exponent –
The exponent field needs to represent both positive and negative
exponents. A bias is added to the actual exponent in order to get the
stored exponent.
3. The Normalised Mantissa –
The mantissa is part of a number in scientific notation or a floating-point
number, consisting of its significant digits. Here we have only 2 digits, i.e.
0 and 1. So a normalised mantissa is one with only one 1 to the left of the
decimal.
IEEE 754 Single precision (32-bit)
• The IEEE-754 single precision floating point standard uses 1-
bit for sign an 8-bit exponent (with a bias of 127) and a 23-bit
significand.
IEEE 754 double precision (64-bit)
• The IEEE-754 double precision standard uses 1-bit for sign
and 11-bit exponent (with a bias of 1023) and a 52-bit
significand.

You might also like