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

Module 4 - Number System and IEEE Floating Point Representation

This document provides an overview of number systems as they relate to computing. It begins by explaining the binary numbering system, which uses only two digits (0 and 1) unlike the human decimal system. Binary arithmetic and various methods for representing negative numbers in binary are then described. The document concludes by detailing the IEEE 754 standard for floating point representation, which defines the format for storing fractional numbers in computers in a normalized way to avoid loss of precision.

Uploaded by

KHUSHI GUPTA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Module 4 - Number System and IEEE Floating Point Representation

This document provides an overview of number systems as they relate to computing. It begins by explaining the binary numbering system, which uses only two digits (0 and 1) unlike the human decimal system. Binary arithmetic and various methods for representing negative numbers in binary are then described. The document concludes by detailing the IEEE 754 standard for floating point representation, which defines the format for storing fractional numbers in computers in a normalized way to avoid loss of precision.

Uploaded by

KHUSHI GUPTA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Module 4 – Number System

BITS Pilani Dr. Jagat Sesh Challa


Pilani Campus
Department of Computer Science & Information Systems
Module Overview

• Binary Numbering System

• Binary Arithmetic

• IEEE Floating Point Representation

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus

Binary Numbering System


The human numbering system

We use digits
0 to 9 -> 10 symbols (digits) (the decimal system)
What is so special about the number 10?
Nothing!

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
The numbering system for
computers

• A simple switch can be ON or OFF – 1 or 0


• Integrated circuits (IC) - billions of switches; allow storage of
huge amounts of information.
• Binary or base-2 number system created using/manipulating just
these 2 states

• Other systems also used: octal (base-8) and hexadecimal (base-


16)

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Decimal vs Binary vs Octal vs
Hexadecimal: An example

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
How a decimal number is
interpreted?
• Eg.: 357
• Digits -> 3 5 7
• Weights-> 10^2 10^1 10^0
• MSD LSD
• Perform sum over Digits*Weights:
• 3*10^2 + 5*10^1 + 7*10^0
• 357

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Binary numbering system
0s and 1s
Binary digits or bits

One bit – can represent 0 and 1 in decimal


Two bits – can represent 0, 1, 2, 3 in decimal
Three bits – can represent 0 to 7 in decimal
In general:
n bits – can represent 0 to 2^n – 1 numbers in decimal

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Binary numbering system

Binary to decimal conversion


E.g.: 10101 (done on the board)

Decimal to binary conversion


E.g.: 16 (done on the board)

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Negative Binary Numbers

• How do we signify negative numbers in arithmetic?

• The – symbol to the left of MSD

• So… 1111 is 15, then -1111 should -15

• But… computers cannot handle any symbol apart from 0


and 1

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Negative Binary Numbers
• To handle negative numbers: left-most bit used to indicate the sign.
• Known by various names: Most Significant Bit (MSB), sign-bit or high-order
bit
• Positive numbers: MSB is 0
• Negative numbers: MSB is 1

• For 8 bit unsigned numbers: range of 0 to 255 (2^8 – 1)


• What about signed numbers?
o -127 to 127 or -128 to 127

• How does the computer know whether to treat a number as signed or


unsigned?
o It cannot. It’s the programmer’s job to tell.
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Negative Binary Numbers
Three schemes for representing negative binary numbers:
• Signed-magnitude representation
• One’s complement
• Two’s complement

• We will discuss them wrt 8 bit integers

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Signed-magnitude
representation
MSB is the sign as usual
7 bits for the magnitude or the value
Range: -127 to 127
Examples:
109 01101101
-109 11101101
127 01111111
-127 11111111
What about zero?

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
1’s complement
As before, MSB indicates the sign. Range: -127 to 127
Negative no. = one’s complement of the positive no.
Invert all the bits -> 1s to 0s and 0s to 1s
Examples:
15 00001111
-15 11110000
85 01010101
-85 10101010
What about zero?

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
2’s complement
2’s complement of a no. = it’s 1’s complement + 1 Most widely used!!
Range: -128 to 127
Example: calculating the two’s complement representation of -15
Decimal 15 00001111
In one’s complement 11110000
Adding 1 +1
In two’s complement 11110001

What about zero?

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus

Binary Arithmetic
Binary arithmetic rules

0 1 is carry. In binary addition carry is discarded


Note: for a
positive number,
its binary
representation in
SMF, 1CT or 2CT
– it is the same
1 Borrow 1 from next high order digit number itself

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 1CT

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 1CT:
Example 1

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 1CT:
Example 2

-3

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 2 CT

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 2 CT:
Example 1

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Substraction using 2CT:
Example 2

-3

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Addition in 2’s Complement

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Addition in 2’s Complement

Ø Overflows occur when the sum does not fit in the given number of bits

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus

IEEE Floating Point Representation


Real numbers in binary

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Real numbers in binary (contd.)

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Floating point representation

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Floating point representation
(contd.)
• BUT…

• Different ways to represent a floating point number


• No fixed position of decimal point
• Loss of precision possible (Why?)

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE 754 floating point
representation

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE 754 floating point
representation (contd.)

Single precision (32 bit)

Double precision (64 bit)

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE floating point
representation

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE floating point
representation

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE floating point
representation

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE floating point
representation

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Converting numbers to IEEE
format
• Convert and normalize the integer part into binary

• Convert the fraction part using the technique explained earlier

• Add the two results and adjust them to produce a proper final
conversion

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Example 1
• 12.375

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Example 2
1 1011 0110 011 0000 0000 0000 0000 0000

( −1) 1 × 210110110 −01111111 × 1.011


= − 1.375 × 255
= −49539595901075456.0
= − 4.9539595901075456 × 1016

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Example 3
• -105.625

Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus

You might also like