Lecture Slides Week4
Lecture Slides Week4
Language
(CS2523)
Week 4
2
Binary Representation of
Floating Point Numbers
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 Standard 754 floating point is the most common representation
today for real numbers on computers, including Intel-based PC’s,
Macs, and most Unix platforms.
4
IEEE 754 Components
5
6
Convert Float to Floating Point Representation – 32 Bit
Float a = 5.2
Binary of 5 = 101
Binary of Fractional part i.e. “.2” would be:
.2*2 0
.4 0
.8 1
.6 1
.2
1.0100110011… E+2
Bias 127; so, 127+2 = 129 = 10000001
0 1 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 …
0:Positive
8
Convert Float to Floating Point Representation – 32 Bit
Float a = 5.2
In Binary
01000000101001100110011001100110
In Hexadecimal
40A66666
9
Example: Biased Notation
10
Convert Float to Floating Point Representation – 32 Bit
11
Convert Float to Floating Point Representation – 32 Bit
12
Convert Float to Floating Point Representation – 32 Bit
13
Convert Float to Floating Point Representation – 8 Bit
Float a = 11.8
Binary of 11 = 1011
Binary of Fractional part i.e. “.8” would be:
.8*2 1
.6 1
.2 0
.4 0
.8
0 1 1 0 0 1 1 1
+(1.0111)2*2(110)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Positive#
15
Convert Float to Floating Point Representation – 8 Bit
Float a = 3.15
Binary of 3 = 11
Binary of Fractional part i.e. “.15” is =
0.00100110011
.15*2 0
.3 0
.6 1
.2 0
.4 0
.8 1
.6 1
.2 0
.4 0
.8 1
.6 1
.2
16
Convert Float to Floating Point Representation – 8 Bit
(3.15)10=(11.00100110011...)2 (Move the fractional point or
dot just before the first one)
(1.100100110011...)2 *21
(1.1001)2 *21 (4 bit mantissa) = (1.1001)2 *2(1)2
(1.1001)2 *2(001)2= (3 bit exponent)
Bias 3; so, 3+1 = 4 = 100
0 1 0 0 1 0 0 1
+(1.1001)2*2(100)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Positive#
17
Convert Float to Floating Point Representation – 8 Bit
18
Convert Float to Floating Point Representation – 8 Bit
19
Convert Float to Floating Point Representation – 8 Bit
20
Convert Float to Floating Point Representation – 8 Bit
21
Convert Float to Floating Point Representation – 8 Bit
22
Convert Float to Floating Point Representation – 8 Bit
Float a = -0.05
Binary of 0 = 0
Binary of Fractional part i.e. “.05” is =
0000110011
.05*2 0
.1 0
.2 0
.4 0
.8 1
.6 1
.2 0
.4 0
.8 1
.6 1
.2
23
Convert Float to Floating Point Representation – 8 Bit
(0.05)10=(0.0000110011...)2 (Move the fractional point or dot
just after the first one)
(00001.10011...)2 *2-5
(1.1001)2 *2-5 (4 bit mantissa)
Bias 3; so, -5+3 = -2 = 010
1 Bit
Sign of Exponent
1 0 1 0 1 0 0 1
-(1.1001)2*2(-010)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Negative#
24
Convert Float to Floating Point Representation – 8 Bit
Float a = 20.38
Binary of 20 = 10100
Binary of Fractional part i.e. “.38” is =
01100001010…
.38*2 0
.76 1
.52 1
.04 0
.08 0
.16 0
.32 0
.64 1
.28 0
.56 1
.12 0
.24
25
Convert Float to Floating Point Representation – 8 Bit
(20.38)10=(10100. 01100001010...)2 (Move the fractional point
or dot just before the first one)
(1.010001100001010...)2 *24
(1.0100)2 *24 (4 bit mantissa)
Bias 3; so, 3+4 = 7 = 111
0 1 1 1 0 1 0 0
+(1.0100)2*2(111)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Positive#
26
Convert Float to Floating Point Representation – 8 Bit
Float a = -7.5
Binary of 7 = 111
Binary of Fractional part i.e. “.5” is =
100000000…
.5*2 1
27
Convert Float to Floating Point Representation – 8 Bit
(-7.5)10=(111. 10000...)2 (Move the fractional point or dot just
before the first one)
(1.1110000...)2 *22
(1.1110)2 *22 (4 bit mantissa)
Bias 3; so, 3+2 = 5 = 101
1 1 0 1 1 1 1 0
-(1.1110)2*2(101)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Negative#
28
Binary Coded Decimal
29
BCD
30
General Concepts
31
Sign Bit (For signed Numbers)
Highest bit indicates the sign. 1 = negative, 0 = positive
sign bit
1 1 1 1 0 1 1 0
Negative
0 0 0 0 1 0 1 0 Positive
32
Sign Extension
33
Two's Complement of a Hexadecimal
• To form the two's complement of a hexadecimal
• Subtract each hexadecimal digit from 15
• Add 1
• Examples:
• 2's complement of 6A3D = 95C2 + 1 = 95C3
• 2's complement of 92F0 = 6D0F + 1 = 6D10
• 2's complement of FFFF = 0000 + 1 = 0001
• No need to convert hexadecimal to binary
34
Hexadecimal Subtraction
• When a borrow is required from the digit to the left, add 16
(decimal) to the current digit's value
16 + 5 = 21
-1 11
C675 C675
- A247 +
5DB9 (2's complement)
242E 242E (same result)
• Last Carry is ignored
35
Hexadecimal Subtraction Practice
Practice: The address of var1 is 00400B20. The address of the next variable after
var1 is 0040A06C. How many bytes are used by var1?
36
Hexadecimal Subtraction
37
Ranges of Signed Integers
The unsigned range is divided into two signed ranges for positive
and negative numbers
38
Character Storage
• Standard ASCII: 7-bit character codes (0 – 127)
• Extended ASCII: 8-bit character codes (0 – 255)
• Unicode: 16-bit character codes (0 – 65,535)
• Unicode standard represents a universal character set
• Defines codes for characters used in all major languages
• UTF-8: variable-length encoding used in HTML
• Encodes all Unicode characters
• Uses 1 byte for ASCII, but multiple bytes for other characters
39
Printable ASCII Codes
0 1 2 3 4 5 6 7 8 9 A B C D E F
2 space ! " # $ % & ' ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ` a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~ DEL
Examples:
ASCII code for space character = 20 (hex) = 32 (decimal)
ASCII code for 'L' = 4C (hex) = 76 (decimal)
ASCII code for 'a' = 61 (hex) = 97 (decimal)
Big-endian and Little-endian
https://www.techtarget.com/searchnetworking/definition/big-endian-and-little-endian
https://uynguyen.github.io/2018/04/30/Big-Endian-vs-Little-Endian/
41
Example
42