0% found this document useful (0 votes)
279 views24 pages

Lecture 6. Fixed and Floating Point Numbers: Prof. Taeweon Suh Computer Science Education Korea University

This document provides a summary of a lecture on fixed and floating point numbers. It discusses: - Fixed point numbers represent rational numbers using a binary point between integer and fraction bits. Addition works by aligning the binary points. - Floating point numbers represent numbers in scientific notation with three fields - sign, exponent, and fraction. The IEEE 754 standard uses biases in the exponent. - IEEE 754 defines single and double precision formats. Single uses 32 bits with a sign, 8 exponent bits, and 23 fraction bits. Double uses 64 bits with 11 exponent and 52 fraction bits for greater precision.

Uploaded by

Panku Rangaree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
279 views24 pages

Lecture 6. Fixed and Floating Point Numbers: Prof. Taeweon Suh Computer Science Education Korea University

This document provides a summary of a lecture on fixed and floating point numbers. It discusses: - Fixed point numbers represent rational numbers using a binary point between integer and fraction bits. Addition works by aligning the binary points. - Floating point numbers represent numbers in scientific notation with three fields - sign, exponent, and fraction. The IEEE 754 standard uses biases in the exponent. - IEEE 754 defines single and double precision formats. Single uses 32 bits with a sign, 8 exponent bits, and 23 fraction bits. Double uses 64 bits with 11 exponent and 52 fraction bits for greater precision.

Uploaded by

Panku Rangaree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

COMP211 Computer Logic Design

Lecture 6. Fixed and Floating Point


Numbers

Prof. Taeweon Suh


Computer Science Education
Korea University
Number Systems

• So far we have studied the following integer number systems in


computer
 Unsigned numbers
 Sign/magnitude numbers
 Two’s complement numbers

• What about rational numbers?


 For example, 2.5, -10.04, 0.75 etc

• Two common notations to represent rational numbers in


computer
 Fixed-point numbers
 Floating-point numbers

Korea Univ
Fixed-Point Numbers
• Fixed point notation has an implied binary point between the integer
and fraction bits
 The binary point is not a part of the representation but is implied
 Example:
• Fixed-point representation of 6.75 using 4 integer bits and 4 fraction bits:

01101100
0110.1100
22 + 21 + 2-1 + 2-2 = 6.75

• The number of integer and fraction bits must be agreed upon by


those generating and those reading the number
 There is no way of knowing the existence of the binary point except through
agreement of those people interpreting the number

Korea Univ
Signed Fixed-Point Numbers

• As with whole numbers, negative fractional numbers can be represented in


two ways
 Sign/magnitude notation
 Two’s complement notation

• Example:
 -2.375 using 8 bits (4 bits each to represent integer and fractional parts)
• 2.375 = 0010 . 0110
• Sign/magnitude notation: 1010 0110
• Two’s complement notation:
1. flip all the bits: 1101 1001
2. add 1: + 1
1101 1010

• Addition and subtraction works easily in computer with 2’s complement


notation like integer addition and subtraction

Korea Univ
Example

• Suppose that we have 8 bits to represent a number


 4 bits for integer and 4 bits for fraction

• Compute 0.75 + (-0.625)


 0.75 = 0000 1100
 0.625 = 0000 1010
 -0.625 in 2’s complement form: 1111 0110

0.75 0000 1100


+ - 0.625 1111 0110
0.125
0000 0010

Korea Univ
Fixed-Point Number Systems

• Fixed-point number systems have a limitation of having a constant


number of integer and fractional bits
 What are the largest and the smallest rational numbers you can represent with
32 bits, assuming 16 bits each for integer and fractional parts?

• Some low-end digital signal processors support fixed-point numbers


 Example: TMS320C550x TI (Texas Instruments) DSPs: www.ti.com

Korea Univ
Floating-Point Numbers
• Floating-point number systems circumvent the limitation of having a constant
number of integer and fractional bits
 They allow the representation of very large and very small numbers

• The binary point floats to the right of the most significant 1


 Similar to decimal scientific notation
 For example, write 27310 in scientific notation:
• Move the decimal point to the right of the most significant digit and increase the exponent:

273 = 2.73 × 102

• In general, a number is written in scientific notation as:


± M × BE
Where,
 M = mantissa
 B = base
 E = exponent
 In the example, M = 2.73, B = 10, and E = 2 (that is, +2.73 × 102)

Korea Univ
Floating-Point Numbers

• Floating-point number representation using 32 bits


 1 sign bit
 8 exponent bits
 23 bits for the mantissa.

1 bit 8 bits 23 bits

Sign Exponent Mantissa

• The following slides show three versions of floating-point


representation with 22810 using a 32-bit
 The final version is called the IEEE 754 floating-point standard

Korea Univ
Floating-Point Representation #1

• First, convert the decimal number to binary


 22810 = 111001002 = 1.11001 × 27

• Next, fill in each field in the 32-bit:


 The sign bit (1 bit) is positive, so 0
 The exponent (8 bits) is 7 (111)
 The mantissa (23 bits) is 1.11001

1 bit 8 bits 23 bits


0 00000111 11 1001 0000 0000 0000 0000
Sign Exponent Mantissa

Korea Univ
Floating-Point Representation #2

• You may have noticed that the first bit of the mantissa is always 1, since the
binary point floats to the right of the most significant 1
 Example: 22810 = 111001002 = 1.11001 × 27

• Thus, storing the most significant 1 (also called the implicit leading 1) is
redundant information

• We can store just the fraction parts in the 23-bit field


 Now, the leading 1 is implied

1 bit 8 bits 23 bits


0 0 00000011
0000111 110 0100 0000 0000 0000 0000
Sign Exponent Fraction

Korea Univ
Floating-Point Representation #3

The exponent needs to represent both positive and negative


• The final change is to use a biased exponent
 The IEEE 754 standard uses a bias of 127
 Biased exponent = bias + exponent
• For example, an exponent of 7 is stored as 127 + 7 = 134 = 100001102

• Thus , 22810 using the IEEE 754 32-bit floating-point standard is

1 bit 8 bits 23 bits


0 10000110 110 0100 0000 0000 0000 0000
Sign Biased Fraction
Exponent

Korea Univ
Example

• Represent -5810 using the IEEE 754 floating-point standard


 First, convert the decimal number to binary
• 5810 = 1110102 = 1.1101 × 25

 Next, fill in each field in the 32-bit number


• The sign bit is negative (1)
• The 8 exponent bits are (127 + 5) = 132 = 10000100(2)

• The remaining 23 bits are the fraction bits: 11010000..000(2)

1 bit 8 bits 23 bits


1 10000100 110 1000 0000 0000 0000 0000
Sign Exponent Fraction

 It is 0xC2680000 in the hexadecimal form


• Check this out with the result of the sample program in the slide# 3

Korea Univ
Floating-Point Numbers: Special Cases

• The IEEE 754 standard includes special cases for numbers that are
difficult to represent, such as 0 because it lacks an implicit leading 1

Number Sign Exponent Fraction


0 X 00000000 00000000000000000000000
∞ 0 11111111 00000000000000000000000
-∞ 1 11111111 00000000000000000000000
NaN X 11111111 non-zero

NaN is used for numbers that don’t exist, such as √-1 or log(-5)

Korea Univ
Floating-Point Number Precision
• The IEEE 754 standard also defines 64-bit double-precision that provides
greater precision and greater range
 Single-Precision (use the float declaration in C language)
• 32-bit notation
• 1 sign bit, 8 exponent bits, 23 fraction bits
• bias = 127
• It spans a range from ±1.175494 X 10-38 to ±3.402824 X 1038

 Double-Precision (use the double declaration in C language)


• 64-bit notation
• 1 sign bit, 11 exponent bits, 52 fraction bits
• bias = 1023
• It spans a range from ±2.22507385850720 X 10-308 to ±1.79769313486232 X 10308

• Most general purpose processors (including Intel and AMD processors) provide
hardware support for double-precision floating-point numbers and operations

Korea Univ
Double Precision Example
• Represent -5810 using the IEEE 754 double precision
 First, convert the decimal number to binary
• 5810 = 1110102 = 1.1101 × 25

 Next, fill in each field in the 64-bit number


• The sign bit is negative (1)
• The 11 exponent bits are (1023 + 5) = 1028 = 10000000100(2)
• The remaining 52 bits are the fraction bits: 11010000..000 (2)

 It is 0xC04D0000_00000000 in the hexadecimal form


• Check this out with the result of the sample program in the slide# 4

Korea Univ
Represent 0.7

• Represent 0.7 in IEEE 754 single precision form


 ½ = 0.5 = 0.1(2) // 0.7-0.5 = 0.2

 1/8 = 0.125 = 0.001(2) // 0.2-0.125=0.075

 1/16 = 0.0625 = 0.0001(2) // 0.075-0.0625=0.0125

 1/128 = 0.0078125 = 0.0000001(2) // 0.0125-0.0078125 =0.0046875

 1/256 = 0.00390625 = 0.00000001(2) // 0.0046875-0.00390625=0.00078125

 ……

 Thus, 0.7 = 0.10110011…(2) = 1.0110011…(2) X 2-1


• In IEEE754 single precision, 0.7 = 0x3F333333
• Check it out with the slide#6

• IEEE754 floating-point standard can’t represent some numbers exactly

Korea Univ
Binary Coded Decimal (BCD)
• Since floating-point number systems can’t represent some numbers exactly such
as 0.1 and 0.7, some application (calculators) use BCD (Binary coded decimal)
 BCD numbers encode each decimal digit using 4 bits with a range of 0 to 9

Decimal BCD Digit


0 0000
1 0001
2 0010
3 0011 BCD fixed-point notation examples
4 0100
1.7 = 0001 . 0111
5 0101
4.9 = 0100 . 1001
6 0110
7 0111
8 1000
9 1001

• BCD is very common in electronic systems where a numeric value is to be


displayed, especially, in systems consisting solely of digital logic (not containing a
microprocessor) - Wiki
Korea Univ
Backup Slides

Korea Univ
Floating-Point Numbers: Rounding
https://www.youtube.com/watch?
v=Iw77CYUT74c
• Arithmetic results that fall outside of the available precision
must round to a neighboring number
• Rounding modes
 Round down
 Round up
 Round toward zero
 Round to nearest

• Example
 Round 1.100101 (1.578125) so that it uses only 3 fraction bits
• Round down: 1.100
• Round up: 1.101
• Round toward zero: 1.100
• Round to nearest: 1.101
 1.625 is closer to 1.578125 than 1.5 is

Korea Univ
Floating-Point Addition with the Same Sign

• Addition with floating-point numbers is not as simple as


addition with 2’s complement numbers

• The steps for adding floating-point numbers with the same


sign are as follows
1. Extract exponent and fraction bits
2. Prepend leading 1 to form mantissa
3. Compare exponents
4. Shift smaller mantissa if necessary
5. Add mantissas
6. Normalize mantissa and adjust exponent if necessary
7. Round result
8. Assemble exponent and fraction back into floating-point format

Korea Univ
Floating-Point Addition Example

Add the following floating-point numbers:

1.5 + 3.25

1.5(10) = 1.1(2) x 20
3.25(10) = 11.01(2) = 1.101(2) x 21

1.1(10) = 0x3FC00000 in IEEE 754 single precision


3.25(10) = 0x40500000 in IEEE 754 single precision

Korea Univ
Floating-Point Addition Example

1. Extract exponent and fraction bits


1 bit 8 bits 23 bits
0 01111111 100 0000 0000 0000 0000 0000
Sign Exponent Fraction
1 bit 8 bits 23 bits
0 10000000 101 0000 0000 0000 0000 0000
Sign Exponent Fraction

For first number (N1): S = 0, E = 127, F = .1


For second number (N2): S = 0, E = 128, F = .101

2. Prepend leading 1 to form mantissa


N1: 1.1
N2: 1.101

Korea Univ
Floating-Point Addition Example

3. Compare exponents
127 – 128 = -1, so shift N1 right by 1 bit

4. Shift smaller mantissa if necessary


shift N1’s mantissa: 1.1 >> 1 = 0.11 (× 21)

5. Add mantissas
0.11 × 21
+ 1.101 × 21
10.011 × 21

Korea Univ
Floating-Point Addition Example

6. Normalize mantissa and adjust exponent if necessary


10.011 × 21 = 1.0011 × 22

7. Round result
No need (fits in 23 bits)

8. Assemble exponent and fraction back into floating-point format


S = 0, E = 2 + 127 = 129 = 10000001 2, F = 001100..

1 bit 8 bits 23 bits


0 10000001 001 1000 0000 0000 0000 0000
Sign Exponent Fraction
4.75(10) = 0x40980000 in the hexadecimal form

Korea Univ

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy