0% found this document useful (0 votes)
22 views88 pages

Cs271 Chapter 04 Numerical Systems

Uploaded by

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

Cs271 Chapter 04 Numerical Systems

Uploaded by

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

Chapter 4.

Data Representation

Instructor: Han Jang

Oregon State University


School of Electrical Engineering and Computer Science
Internal representation
— Just like everything else in a computer, the
representation of data is implemented
electrically
◦ switches set to OFF or ON
— Use the binary number system to represent
numeric values electrically.
— Switches are grouped into bytes, words, etc., to
represent a numerical value in the binary
system
◦ byte = 8-bits, word = 2 bytes (16 bits), etc.

2
External Representation
— Binary Number System
◦ has 2 digits: 0 and 1 (binary digit)
◦ place values determined by powers of 2.
◦ can uniquely represent any integer value in theory

— In practice, representation is finite inside the


computer
◦ Representations with too many digits get truncated.

3
Binary Representation
— Place values (right-to-left) are 20, 21, 22, 23, 24, etc.
— Bits are numbered (right-to-left) starting at 0.
— Place value depends on number of "bits" defined.
— Example:
◦ A 16-bit integer is transcribed as 0000 0000 1011 0010
(assuming red is "on")

— To convert to its familiar decimal representation, just


add up the place values of the places that are "on".

4
Converting binary to decimal

0000 0000 1011 0010 can be transcribed in decimal form.


à 2 + 16 + 32 + 128 = 178

5
Converting decimal to binary
Example: 157 => 0b10011101

— Method 1: Removing largest powers of 2


157 – 128 = 29 1 in 128s place
29 – 16 = 13 0 in 64s place, 0 in 32s place, 1 in 16s place
13 – 8 = 5 1 in 8s place
5–4=1 1 in 4s place
1–1=0 0 in 2s place, 1 in 1s place

6
Converting decimal to binary
Example: 157 => 0b10011101

— Method 1: Removing largest powers of 2


157 – 128 = 29 1 in 128s place
29 – 16 = 13 0 in 64s place, 0 in 32s place, 1 in 16s place
13 – 8 = 5 1 in 8s place
5–4=1 1 in 4s place
1–1=0 0 in 2s place, 1 in 1s place

0b1 _ _ _ _ _ _ _
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

7
Converting decimal to binary
Example: 157 => 0b10011101

— Method 1: Removing largest powers of 2


157 – 128 = 29 1 in 128s place
29 – 16 = 13 1 in 16s place
13 – 8 = 5 1 in 8s place
5–4=1 1 in 4s place
1–1=0 0 in 2s place, 1 in 1s place

0b1 _ _ 1 _ _ _ _
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

8
Converting decimal to binary
Example: 157 => 0b10011101

— Method 1: Removing largest powers of 2


157 – 128 = 29 1 in 128s place
29 – 16 = 13 1 in 16s place
13 – 8 = 5 1 in 8s place
5–4=1 1 in 4s place
1–1=0 0 in 2s place, 1 in 1s place

0b1 _ _ 1 1 _ _ _
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

9
Converting decimal to binary
Example: 157 => 0b10011101

— Method 1: Removing largest powers of 2


157 – 128 = 29 1 in 128s place
29 – 16 = 13 1 in 16s place
13 – 8 = 5 1 in 8s place
5–4=1 1 in 4s place
1–1=0 0 in 2s place, 1 in 1s place

0b1 _ _ 1 1 1 _ _
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

10
Converting decimal to binary
Example: 157 => 0b10011101

— Method 1: Removing largest powers of 2


157 – 128 = 29 1 in 128s place
29 – 16 = 13 1 in 16s place
13 – 8 = 5 1 in 8s place
5–4=1 1 in 4s place
1–1=0 1 in 1s place

0b1 _ _ 1 1 1 _ 1
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

11
Converting decimal to binary
Example: 157 => 0b10011101

— Method 1: Removing largest powers of 2


157 – 128 = 29 1 in 128s place
29 – 16 = 13 1 in 16s place
13 – 8 = 5 1 in 8s place
5–4=1 1 in 4s place
1–1=0 1 in 1s place
Then write zero where it is off

0b1 0 0 1 1 1 0 1
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

12
Converting decimal to binary
Example: 157 => 0b10011101

— Method 2: Successive division by 2


157 ÷ 2 = 78 R1
78 ÷ 2 = 39 R0
39 ÷ 2 = 19 R1
19 ÷ 2 = 9 R1
9÷2 =4 R1
4÷2 =2 R0
2÷2 =1 R0
1÷2 =0 R1 (Write remainders, bottom to top)

0b1 0 0 1 1 1 0 1
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
13
Converting decimal to binary
Example: 157 => 0b10011101
2 157

— Method 2: Successive division by 2 2 78 ..R 1


157 ÷ 2 = 78 R1 39 ..R 0
2
78 ÷ 2 = 39 R0
39 ÷ 2 = 19 R1 2 19 ..R 1
19 ÷ 2 = 9 R1 9 ..R 1
2
9÷2 =4 R1
4÷2 =2 R0 2 4 ..R 1
2÷2 =1 R0
2 2 ..R 0
1÷2 =0 R1
2 1 ..R 0

0b1 0 0 1 1 1 0 1 0 ..R 1

27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
14
Hexadecimal Representation
— The hex number system has 16 digits:
◦ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
— Place values (right-to-left) are ...
◦ 160, 161, 162, 163, 164, etc.
— Hexadecimal is commonly used for easily
converting binary to a more manageable
form.
◦ 16 = 24, thus 4 binary digits can be represented
as one hex digit.

15
Practice
— Convert 6077(decimal) into Hex number.
◦ First, convert into 16-bit Binary
◦ Then transcribe to Hex

16
Representing negative integers
— Must specify size!
◦ Specify n: number of bits (8, 16, 32, etc.)
◦ There are 2n possible "codes“

— Separate the "codes" so that half of them represent


negative numbers.
◦ Note that exactly half of the codes have 1 in the "leftmost" bit.
– Most Significant Bit: a bit of the highest digit
– Least Significant Bit: a bit of the lowest digit

0b _ _ _ _ _ _ _ _ _
M L
S S
B B 18
Binary form of negative numbers
— Several methods, each with disadvantages.
— We will focus on two’s-complement form
◦ Signed magnitude representation (SMR)
◦ One’s complement
◦ Two’s complement

— Two’s complement for negative numbers :


◦ specify number of bits
◦ start with binary representation of |x|
◦ change every bit to its opposite, then add 1 to the result.

19
Signed number representations
Decimal Binary Negative SMR One’s Two’s
0 0000 -0 1000 1111 0000
1 0001 -1 1001 1110 1111
2 0010 -2 1010 1101 1110
3 0011 -3 1011 1100 1101
4 0100 -4 1100 1011 1100
5 0101 -5 1101 1010 1011
6 0110 -6 1110 1001 1010
7 0111 -7 1111 1000 1001
8 1000 -8 - - 1000

20
Binary form of negative numbers
— Example: -13 in 16-bit twos-complement
◦ |-13| = 13 = 0000 0000 0000 1101
◦ ones-complement is 1111 1111 1111 0010
◦ add 1 to get 1111 1111 1111 0011 = -13

— Note that -(-13) should give 13. Try it.

— Hexadecimal representation?
◦ Convert binary to hex in the usual way
◦ -13 = 1111 1111 1111 0011 = FFF3h = 0xfff3

— Convert negative binary to decimal?


◦ Find twos complement, convert, and prepend a minus sign. 21
n-bit twos-complement form
— The 2n possible codes give
◦ Zero (all bits are zero)
◦ (2n-1 – 1) positive numbers
◦ 2n-1 negative numbers
— Note: zero is its own complement
— Note: there is one “weird” number
◦ 01111111 + 1 = 10000000
◦ 127 + 1 = -128
◦ (inconsistent with rules of arithmetic)
— 127 is the largest number that can be represented in 8
bits. This means that -(-128) cannot be represented with
8 bits.
— i.e., the 2's-complement of 10000000 is 10000000
22
Signed or Unsigned?
— A 16-bit representation could be used for signed or
unsigned numbers
◦ 16-bit unsigned range is 0 .. 65535
◦ 16-bit signed range is -32768 .. +32767
— Both forms use the same 65536 codes (216 = 65536)
— Example:
◦ 1010101010101010 unsigned is 43690 decimal
◦ 1010101010101010 signed is -21846 decimal
— Example:
◦ 1111111111111111 unsigned is 65535 decimal
◦ 1111111111111111 signed is -1 decimal
— Programs tell the computer which form is being used.
23
Negative hex (signed integers)
— How can you tell if a hexadecimal representation of a
signed integer is negative?
◦ Recall that a 16-bit signed integer is negative if the leftmost bit is
1
— 16-bit (4 hex digits) examples:
◦ 0x7a3e is positive
◦ 0x8a3e is negative
◦ 0xFFFF is negative

24
Character and control codes
— Letters, digits, special characters … are represented
internally as numbers
— ASCII 256 codes (1-byte)
◦ e.g., 'A' … 'Z' are codes 65 - 90
◦ e.g., '0' … '9' are codes 48 - 57
— Unicode 65,536 codes (2-byte)
— Some codes are used for controlling devices
◦ e.g., code 10 is “new line” for output device
◦ e.g., code 27 is Esc (“escape” key)
— Device controllers translate codes (device-dependent)
— All keyboard input is character (including digits)

25
ASCII Codes

26
Digits
— Digits entered from the keyboard are characters
◦ E.G., ‘0’ is character number 48, … ‘9’ is character number 57

— What happens if we add ‘3’ + ‘5’?


◦ ‘3’ => 51
◦ ‘5’ => 53
◦ The answer is 104 which is ‘h’

— Numeric data types require conversion by the


input/output operations

27
Neutral representation
— Inside the computer
◦ Bytes, words, etc., can represent a finite number of combinations
of off/on switches.
◦ Each distinct combination is called a code.
◦ Each code can be used to represent:
– numeric value
– memory address
– machine instruction
– keyboard character
– other characters

— Representation is neutral.
◦ The operating system and the programs decide how to interpret
the codes.
28
Interpreting codes
— It is especially important to learn to interpret
hexadecimal (external representation) codes.
◦ Frequently used by assembly and debugging systems

29
Arithmetic operations
— The following examples use 8-bit two’s-complement
operands
◦ Everything extends to 16-bit, 32-bit, n-bit representations.
◦ What is the range of values for 8-bit operands?
– Signed: -128 to 127
– Unsigned: 0 to 255

— The usual arithmetic operations can be performed


directly in binary form with n-bit representations

30
Binary Addition
— Specify result size (bits)
— Binary addition table: + 0 1
0 0 1
1 1 10

— Use the usual rules of add and carry


◦ With two operands, the carry bit is never greater than one
◦ 0+0+1 =01, 0+1+1 =10, 1+0+1 =10, 1+1+0 =10, 1+1+1 =11
— Example:
00101101 10101101
+ 00011110 + 10011110
01001011 101001011

— How does overflow occur?


31
Binary Subtraction
— Use the usual rules
◦ Order of operands
◦ Borrow and subtract

— Example: 00101101
- 00011110
00001111

— … or negate and add (-00011110 = 11100010)


◦ Example:
00101101
+ 11100010
00001111

32
Verification
— Perform operation on binary operands
— Convert result to decimal
— Convert operands to decimal
— Perform operation on decimal operands
— [Convert result to binary]
— Compare results

33
Binary Multiplication
— Usual algorithm (45 × 5 )
00101101
× 101
00101101
001011010
11100001

34
Binary Multiplication
— Usual algorithm (45 × 5 ) — Repeated addition (45 + 45 +… )
00101101 00101101
× 101 + 00101101
00101101 + 00101101
001011010 + 00101101
11100001 + 00101101
11100001

35
Binary Multiplication
— Usual algorithm (45 × 5 ) — Repeated addition (45 + 45 +… )
00101101 00101101
× 101 + 00101101
00101101 + 00101101
001011010 + 00101101
11100001 + 00101101
11100001
— … or shift left (and add leftovers, if multiplier is not a
power of 2) (e.g., 45 x 5 = 45 × 4 + 45 )
0010110100 (00101101<<2) is 45 × 4
+ 00101101
1110001
11100001

— Check for overflow


36
Binary Division
— Usual algorithm (45 ÷ 7 )

110 : Quotient
111 101101
111
1000
111
11 : Remainder

37
Binary Division
— Usual algorithm (45 ÷ 7 ) — Repeated subtraction
◦ Count … until remainder is less than
divisor
00101101
110 : Quotient
- 111
111 101101 - 111
111 #count = Quotient
1000 - 111


111
11 : Remainder 11 : Remainder

38
Binary Division
— Usual algorithm (45 ÷ 7 ) — Repeated subtraction
◦ Count … until remainder is less than
divisor
00101101
110 : Quotient
- 111
111 101101 - 111
111 #count = Quotient
1000 - 111


111
11 : Remainder 11 : Remainder

— If divisor is a power of 2, shift right and keep track of


dropped bits. (e.g., 45 ÷ 8 )
00101101
=> 00000101101 (00101101>>3) is 45 ÷ 8
1110001
Quotient Dropped: Remainder

— Check for remainder


39
Arithmetic operations
— Note: all of the integer arithmetic operations can be
accomplished using only
◦ add
◦ complement

— Addition: add
— Subtraction: complement and add
— Multiplication: repeated add
— Division: repeated subtract
— Comparison: non-destructive subtract

40
Byte-ordering
— When it takes more than one byte to represent a value
— Big-endian
◦ Bytes are ordered left -> right (most significant to least
significant) in each word
◦ Used in Motorola architectures (Mac) and others
— Little-endian
◦ Bytes are ordered least significant to most significant in each
word
◦ Used in Intel architectures (e.g., IA-32)
— For both schemes:
◦ Within each byte, bit values are stored left -> right (as usual)
◦ Each character is one byte
◦ Strings are stored in byte order.
— Problem: communicating between architectures.
41
Big Endian and Little Endian

42
Byte-ordering (big-endian)
— Example 32-bit integer: -1234
11111111 11111111 11111011 00101110
FF FF FB 2E
Byte3 Byte2 Byte1 Byte0

— Big-endian (big end first)


Memory addresses:
1004 1005 1006 1007
11111111 11111111 11111011 00101110
FF FF FB 2E
Byte3 Byte2 Byte1 Byte0

43
Byte-ordering (little-endian)
— Example 32-bit integer: -1234
11111111 11111111 11111011 00101110
FF FF FB 2E
Byte3 Byte2 Byte1 Byte0

— Little-endian (little end first)


Memory addresses:
1004 1005 1006 1007
00101110 11111011 11111111 11111111
2E FB FF FF
Byte0 Byte1 Byte2 Byte3

44
Communication
— Internet communication must be consistent across
architectures

— Network order is always big-endian

— More about this is your networking courses

45
Floating-point values
— “decimal” means “base ten”

— “floating-point” means “a number with an integral part


and a fractional part
◦ Sometimes call “real”, “float”

— Generic term for “decimal point” is “radix point”

46
Converting floating-point
(decimal - binary) - Subtraction
25 24 23 22 21 20 2-1 2-2 2-3 2-4 2-5
32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125

Integer part Fractional part

— Method 1: Removing largest powers of 2


— Example: 6.25 (decimal) = 110.01 (binary)

47
Converting floating-point
(decimal - binary) - Subtraction
25 24 23 22 21 20 2-1 2-2 2-3 2-4 2-5
32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125
1

Integer part Fractional part

— Method 1: Removing largest powers of 2


— Example: 6.25 (decimal) = 110.01 (binary)
6.25 – 4 = 2.25 1 in 4s place

48
Converting floating-point
(decimal - binary) - Subtraction
25 24 23 22 21 20 2-1 2-2 2-3 2-4 2-5
32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125
1 1

Integer part Fractional part

— Method 1: Removing largest powers of 2


— Example: 6.25 (decimal) = 110.01 (binary)
6.25 – 4 = 2.25 1 in 4s place
2.25 – 2 = 0.25 1 in 2s place

49
Converting floating-point
(decimal - binary) - Subtraction
25 24 23 22 21 20 2-1 2-2 2-3 2-4 2-5
32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125
1 1 1

Integer part Fractional part

— Method 1: Removing largest powers of 2


— Example: 6.25 (decimal) = 110.01 (binary)
6.25 – 4 = 2.25 1 in 4s place
2.25 – 2 = 0.25 1 in 2s place
0.25 – 0.25 = 0 1 in 0.25s place,

50
Converting floating-point
(decimal - binary) - Subtraction
25 24 23 22 21 20 2-1 2-2 2-3 2-4 2-5
32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125
0 0 0 1 1 0 0 1 0 0 0

Integer part Fractional part

— Method 1: Removing largest powers of 2


— Example: 6.25 (decimal) = 110.01 (binary)
6.25 – 4 = 2.25 1 in 4s place
2.25 – 2 = 0.25 1 in 2s place
0.25 – 0.25 = 0 1 in 0.25s place,

(Write zero where it is off)


51
Converting floating-point
(decimal - binary) – Div/Mult

— Example: 6.8125 (decimal) = _ _ _._ _ _ _ (binary)


— Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.8125 x 2 = 1.625
.625 x 2 = 1.25
.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom) 52
Converting floating-point
(decimal - binary) – Div/Mult

— Example: 6.8125 (decimal) = 1 _ _._ _ _ _ (binary)


— Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.8125 x 2 = 1.625
.625 x 2 = 1.25
.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom) 53
Converting floating-point
(decimal - binary) – Div/Mult

— Example: 6.8125 (decimal) = 11_._ _ _ _ (binary)


— Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.8125 x 2 = 1.625
.625 x 2 = 1.25
.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom) 54
Converting floating-point
(decimal - binary) – Div/Mult

— Example: 6.8125 (decimal) = 110._ _ _ _ (binary)


— Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.8125 x 2 = 1.625
.625 x 2 = 1.25
.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom) 55
Converting floating-point
(decimal - binary) – Div/Mult

— Example: 6.8125 (decimal) = 110.1 _ _ _ (binary)


— Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.8125 x 2 = 1.625
.625 x 2 = 1.25
.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom) 56
Converting floating-point
(decimal - binary) – Div/Mult

— Example: 6.8125 (decimal) = 110.11_ _ (binary)


— Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.8125 x 2 = 1.625
.625 x 2 = 1.25
.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom) 57
Converting floating-point
(decimal - binary) – Div/Mult

— Example: 6.8125 (decimal) = 110.110_ (binary)


— Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.8125 x 2 = 1.625
.625 x 2 = 1.25
.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom) 58
Converting floating-point
(decimal - binary) – Div/Mult

— Example: 6.8125 (decimal) = 110.1101 (binary)


— Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.8125 x 2 = 1.625
.625 x 2 = 1.25
.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom) 59
Converting floating-point
(decimal - binary)

— Example: 6.2 (decimal) ≈110.001100110011… (binary)


— Method:
6 = 110 (Integral part: convert in the usual way)

.2 x 2 = 0.4 (Fractional part: successive multiplication by 2)


.4 x 2 = 0.8
.8 x 2 = 1.6
.6 x 2 = 1.2
.2 x 2 = 0.4 (Stop when fractional part repeats or size is exceeded)

— 110.0011 0011 0011


60
Normalizing binary numbers
— In decimal, shift the decimal point right/left until the first
“1s”, and multiply by the base 10 raised into power
based on how many positions the decimal point was
right(-)/left(+)
◦ 1530 = 1.530 x 103
◦ -0.0345 = - 3.45 x 10-2

— In binary, when we normalize numbers, shift the radix


point right/left until the first “1”, and multiply with the
base 2 into some power.
◦ 101.1 = 1.011 x 22
◦ -0.001011 = -1.011 x 2-3

61
IEEE 754 standard
— Most use a completely different representation (IEEE
standard) and a separate ALU (Floating-Point unit)
— 3 Levels of precision
◦ Single (32-bit), Double (64-bit), and Extended (80-bit)
— 3 parts code structure
0 0……0 0……………0

Sign bit
Normalized mantissa
Biased exponent
Three-part code structure
(Single precision: 32-bit)

0 0……0 0……………0

Sign bit: 1 bit


Normalized mantissa:
Biased exponent: Single: 23 bits
Single: 8 bits
Three-part code structure
(Double precision: 64-bit)

0 0……0 0……………0

Sign bit: 1 bit


Normalized mantissa:
Biased exponent: Double: 52 bits
Double: 11 bits
Three-part code structure
(Extended precision: 80-bit)

0 0……0 0……………0

Sign bit: 1 bit


Normalized mantissa:
Biased exponent: Extended: 64 bits
Extended: 15 bits
IEEE 754 standard
(Three-part code structure)

0 0……0 0……………0

Sign bit: 1 bit


Normalized mantissa:
Biased exponent: Single: 23 bits
Single: 8 bits Double: 52 bits
Double: 11 bits Extended: 64 bits
Extended: 15 bits
Three-part code structure
Sign Exponent
+ 𝟏. 𝟎𝟏𝟏 𝐱 𝟐𝟐
Normalized Mantissa
◦ Sign bit: 1 bit - Positive: 0, Negative: 1
◦ Biased exponent: Exponent + Bias
– Bias: A constant equal to 2!"# − 1 , where k = # of
exponent bits, 8 (single), 11(double) or 15(extended)
– Single: 127 (= 2!"# − 1)
– Double: 1023 (= 2##"# − 1)
– Extended: 16383 (= 2#$"# − 1)
◦ Normalized mantissa: The fractional part of the
normalized number
– Single: 23 bits
– Double: 52 bits
– Extended: 64 bits
Example: Decimal 6.25 to
IEEE754 Single Precision
— Find sign bit: Positive number = 0

68
Example: Decimal 6.25 to
IEEE754 Single Precision
— Find sign bit: Positive number = 0
— Convert to binary: 6.25 =>110.01
◦ Method: Successive division by 2 for integer part,
multiplication by 2 for floating part.
6÷2=3R0
3÷2=1R1
1÷2=0R1 (Stop when integer part is 0,
Write remainders, bottom to top)

.25 x 2 = 0.5
.5 x 2 = 1.0 (Stop when fractional part is 0,
Write integers, top to bottom)

69
Example: Decimal 6.25 to
IEEE754 Single Precision
— Find sign bit: Positive number = 0
— Convert to binary: 110.01
— Normalize the binary number:
◦ +1.1001 x 22

70
Example: Decimal 6.25 to
IEEE754 Single Precision
— Find sign bit: Positive number = 0
— Convert to binary: 110.01
— Normalize the binary number: +1.1001 x 22
— Calculate biased exponent: Exponent + Bias
◦ Exponent = 2
◦ Bias = 127 in single precision

71
Example: Decimal 6.25 to
IEEE754 Single Precision
— Find sign bit: Positive number = 0
— Convert to binary: 110.01
— Normalize the binary number: +1.1001 x 22
— Calculate biased exponent = Exponent + Bias = 129
◦ Exponent = 2
◦ Bias = 127 in single precision
— Convert the biased exponent to binary
◦ 129 (in decimal) = 1000 0001 (in binary)

72
Example: Decimal 6.25 to
IEEE754 Single Precision
— Find sign bit: Positive number = 0
— Convert to binary: 110.01
— Normalize the binary number: +1.1001 x 22
— Calculate biased exponent: Exponent + Bias = 129
◦ Exponent = 2
◦ Bias = 127 in single precision
— Convert the biased exponent to binary
◦ 129 (in decimal) = 1000 0001 (in binary)
— Find the normalized mantissa:
◦ 1001

73
Example: Decimal 6.25 to
IEEE754 Single Precision
— Find sign bit: Positive number = 0
— Convert to binary: 110.01
— Normalize the binary number: +1.1001 x 22
— Calculate biased exponent: Exponent + Bias = 129
◦ Exponent = 2
◦ Bias = 127 in single precision
— Convert the biased exponent to binary
◦ 129 (in decimal) = 1000 0001 (in binary)
— Find the normalized mantissa: 1001
— Fill the code bits:
0 1000 0001 1001 0000 0000 0000 0000 000
1-bit 8-bit 23-bit
Sign Biased exponent Normalized mantissa 74
32-bit Example: 6.25
— 6.25 in IEEE single precision
6.25 (decimal) = 110.01 (binary)
Move the radix point until a single 1 appears on the left,
and multiply by the corresponding power of 2
= 1.1001 x 22
… the sign bit is 0 (positive)
… the “biased” exponent is 2 + 127 = 129 = 10000001
… and the “normalized” mantissa is 1001 (drop the 1, and
zero-fill).
Rearrange 0 10000001 10010000000000000000000
0100 0000 1100 1000 0000 0000 0000 0000
= 0x40C80000
75
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000

77
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign:

78
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign: 1
◦ 8-bit Biased Exponent:

79
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign: 1
◦ 8-bit Biased Exponent: 100 0001 1
– Biased Exponent = Exponent + Bias
– Convert to decimal:

80
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign: 1
◦ 8-bit Biased Exponent: 100 0001 1
– Biased Exponent = Exponent + Bias
– Convert to decimal: 100 0001 1 => 1000 0011 => 128 + 2 + 1 = 131
– Subtract Bias:

81
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign: 1
◦ 8-bit Biased Exponent: 100 0001 1
– Biased Exponent = Exponent + Bias
– Convert to decimal: 100 0001 1 => 1000 0011 => 128 + 2 + 1 = 131
– Subtract Bias: 131 – 127 = 4
◦ Normalized Mantissa:

82
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign: 1
◦ 8-bit Biased Exponent: 100 0001 1
– Biased Exponent = Exponent + Bias
– Convert to decimal: 100 0001 1 => 1000 0011 => 128 + 2 + 1 = 131
– Subtract Bias: 131 – 127 = 4
◦ Normalized Mantissa: 000 0111 0000 0000 0000 0000
— Form the normalized binary number:

-1.0000111 x 24
83
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign: 1
◦ 8-bit Biased Exponent: 100 0001 1
– Biased Exponent = Exponent + Bias
– Convert to decimal: 100 0001 1 => 1000 0011 => 128 + 2 + 1 = 131
– Subtract Bias: 131 – 127 = 4
◦ Normalized Mantissa: 000 0111 0000 0000 0000 0000
— Form the normalized binary number: - 1.0000111 x 24
— Unnormalized binary number:
84
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign: 1
◦ 8-bit Biased Exponent: 100 0001 1
– Biased Exponent = Exponent + Bias
– Convert to decimal: 100 0001 1 => 1000 0011 => 128 + 2 + 1 = 131
– Subtract Bias: 131 – 127 = 4
◦ Normalized Mantissa: 000 0111 0000 0000 0000 0000
— Form the normalized binary number: - 1.0000111 x 24
— Unnormalized binary number: -10000.111
— Convert to decimal:
85
IEEE754 Single Precision to
Decimal
— Number: 0xC1870000
— Find binary:
◦ 1100 0001 1000 0111 0000 0000 0000 0000
— Find components
◦ 1-bit Sign: 1
◦ 8-bit Biased Exponent: 100 0001 1
– Biased Exponent = Exponent + Bias
– Convert to decimal: 100 0001 1 => 1000 0011 => 128 + 2 + 1 = 131
– Subtract Bias: 131 – 127 = 4
◦ Normalized Mantissa: 000 0111 0000 0000 0000 0000
— Form the normalized binary number: - 1.0000111 x 24
— Unnormalized binary number: -10000.111
— Convert to decimal: -(24 + 0.5 + 0.25 + 0.125)= -16.875
86
32-bit Example: 0xC1870000
— What decimal floating-point number is represented by
0xC1870000?
1100 0001 1000 0111 0000 0000 0000 0000
1 10000011 00001110000000000000000
… the sign is negative
… the “unbiased” exponent is 131 - 127 = 4
… and the “unnormalized” mantissa is
1.00001110000000000000000
(insert the 1 left of the radix point).
Move the radix point 4 places to the right: 10000.111
— -10000.111 = -16.875

87
Practice
— Show the IEEE Standard 754 single-precision binary (32-bit)
representation of the floating-point number -23.625.

◦ Normalized Binary:

◦ Sign:

◦ Biased Exponent:

◦ Normalized Mantissa:

◦ Form binary code:

88
Practice II
— Convert the number in IEEE representation below to
decimal.
◦ Number:
0 10000000101 1110100110000000000000000000000000000000000000000000

◦ Sign: Positive = 0
◦ Biased Exponent: = 100 0000 0101 (11-bit)
– Convert to decimal: 100 0000 0101 => 1 + 22 + 210 = 1029
– Exponent = Biased exponent – bias = 1029 - 1023 = 6
◦ Unnormalized Mantissa:
– Normalized Mantissa = 1.111010 011 x 26
– 1111010.011
◦ Decimal number: 122.375
– Integer: 11110 => 2 + 23 + 24+ 25 + 26 = 122
– Fractional: 0.011 => 0.25 + 0.125 = 0.375
90
Questions?

92

You might also like