0% found this document useful (0 votes)
51 views100 pages

Chapter 02-Part I

Uploaded by

kk
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)
51 views100 pages

Chapter 02-Part I

Uploaded by

kk
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/ 100

02: Data Representation and Arithmetic

IT1206- Computer Systems

Level I - Semester 1

© 2020 e-Learning Centre, UCSC


List of Sub Topics

• Positinal Numbering System


• Decimal-Binary Conversion
• Unsigned whole number conversion
• Fraction conversion
• Power of two Radices conversion
• Signed Integer Representation
• Signed Magnitude
• Two’s complement
• Floating Point Representation
• Character Codes

© 2020 e-Learning Centre, UCSC 2


What is a bit ?

• A bit is the smallest unit of data on a machine.


• A bit can hold only one of two values: 0 or 1
• In a computer, a bit represents one of possible two
states.
• Because bits are so small, you rarely work with
information one bit at a time.

© 2020 e-Learning Centre, UCSC 3


What is a byte ?

• Conventionally, a group of 8 bits are named as a byte.


Counting starts with zero

7 6 5 4 3 2 1 0 Position

1 1 0 1 1 0 1 0
A byte represents a group of bits

Most Least
Significant Bit Significant Bit

© 2020 e-Learning Centre, UCSC 4


Word

• A word is a fixed-sized piece of data which is handled


as a unit by the CPU of a computer.
• E.g. 32 bit, 64 bit, and so on.
• A word may consist with several bytes.

© 2020 e-Learning Centre, UCSC 5


Units of Data Measurement

• 8 Bits = 1 Byte
• 1024 Bytes = 1 Kilobyte (KB)
• 1024 KB = 1 Megabyte (MB)
• 1024 MB = 1 Gigabyte (GB)
• 1024 GB = 1 Terabytes (TB)
• 1024 TB = 1 Petabytes (PB)
• 1024 PB = 1 Exabyte
• 1024 EB = 1 Zettabyte
• 1024 ZB = 1 Yottabyte

© 2020 e-Learning Centre, UCSC 6


Positional Numbering System

• A positional numbering system is the representation of


numbers by an ordered set of numerals symbols
(digits) in which the value of a numeral symbol
depends on its position.
• We all are familiar with base (radix) 10 number system.
• In based 10 number system, number 283.75 means;
2 × 102 + 8 × 101 + 3 × 100 + 7 × 10−1 + 5 × 10−2

2 8 3 7 5
102 101 100 10-1 10-2

© 2020 e-Learning Centre, UCSC 7


Number Systems

• There are many other number systems


• Decimal [0,1,2,3,4,5,6,7,8,9]
• Binary [0,1]
• Hexa Decimal [0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F]
• Octal [0,1,2,3,4,5,6,7]

© 2020 e-Learning Centre, UCSC 8


Converting Decimal to Binary (whole numbers)

• To convert decimal whole number to binary, start with


the integer part in the given number and divide it by 2
• Keep the resulting quotient and the remainder
separately.
• Continue dividing the quotient by 2 until you get a
quotient of zero.
• At the end just write out the remainders in the reverse
order.

© 2020 e-Learning Centre, UCSC 9


Converting Decimal to Binary (whole numbers)

123 11110112
÷2
61 → remainder 1
÷2
30 → remainder 1
÷2
15 → remainder 0
÷2
7 → remainder 1
÷2
3 → remainder 1
÷2
1 → remainder 1
÷2
0 → remainder 1

© 2020 e-Learning Centre, UCSC 10


Converting Decimal to Binary (fractional numbers)

• To convert decimal fraction to binary, start with the


fractional part in the given number and multiply it by 2.
• Keep the resulting integer and fractional parts separately.
• Continue multiplying by 2 until you get a resulting
fractional part equal to zero.
• At the end just write out the integer parts from the results
of each multiplication starting from the first multiplication.
0.375 x 2 = 0 + 0.75
0.75 x 2 = 1 + 0.5
0.5 x 2 = 1 + 0

0.37510 = 0.0112

© 2020 e-Learning Centre, UCSC 11


Activities

Convert following numbers to binary


• 2273
• 12478
• 0.2487
• 0.99724
• 347.35
• 437.639

© 2020 e-Learning Centre, UCSC 12


Converting Binary to Decimal

• If we want to convert 101.112 to decimal;

1 0 1 1 1
22 21 20 2-1 2-2

1 × 22 + 0 × 21 + 1 × 20 + 1 × 2−1 + 1 × 2−2

4 + 0 + 1 + 0.5 + 0.25

5.75

© 2020 e-Learning Centre, UCSC 13


Converting Between Power-of-Two Radices

• Hexadecimal and Octal are two number systems where


their radices are of power of two (16 = 24 and 8 = 23).
• We can easily convert numbers between power of two
radices number systems.

© 2020 e-Learning Centre, UCSC 14


Hexadecimal

HEX Bit Pattern HEX Bit Pattern


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

© 2020 e-Learning Centre, UCSC 15


Octal

Octal Bit Pattern


0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

© 2020 e-Learning Centre, UCSC 16


Converting Between Power-of-Two Radices

• Ex. 1100100111012
• Conversion to hexadecimal
1 1 0 0 1 0 0 1 1 1 0 1 Binary

C 9 D Hexadecimal

• Conversion to octal
1 1 0 0 1 0 0 1 1 1 0 1 Binary

6 2 3 5 Octal

© 2020 e-Learning Centre, UCSC 17


Binary Addition

• 0+0=0
• 0+1=1
• 1+0=1
• 1 + 1 = 10 (carry: 1)

• E.g.
11 1 1 1 (carry)
0 1 1 0 1
+ 1 0 1 1 1
= 10 0 1 0 0

© 2020 e-Learning Centre, UCSC 18


Binary Subtraction

• 0-0=0
• 0 - 1 = 1 (with borrow)
• 1-0=1
• 1-1=0

• E.g.
* * * (borrow)
1 0 1 1 0 1
- 0 1 0 1 1 1
= 0 1 0 1 1 0

© 2020 e-Learning Centre, UCSC 19


Binary Multiplication

• E.g.
1 0 1 1
x 1 0 1 0
0 0 0 0
+ 1 0 1 1
+ 0 0 0 0
+ 1 0 1 1
= 1 1 0 1 1 1 0

© 2020 e-Learning Centre, UCSC 20


Binary Division

• E.g.
1 0 1 Quotient

1 0 1 1 1 0 1 1
- 1 0 1
1 1
- 0 0
1 1 1
- 1 0 1
1 0 Remainder

© 2020 e-Learning Centre, UCSC 21


Representing Numbers

• Problems of number representation


• Positive and negative
• Radix point
• Range of representation

• Different ways to represent numbers


• Unsigned representation: non-negative integers
• Signed representation: integers
• Floating-point representation: fractions

© 2020 e-Learning Centre, UCSC 22


Unsigned Binary Numbers

• Unsigned binary numbers


• Have 0 and 1 to represent numbers
• Only positive numbers stored in binary
• The Smallest binary number that can be stored
using 8 bits would be 0 0 0 0 0 0 0 0
which equals to 0
• The largest binary number would be 1 1 1 1 1 1 1 1

which equals to 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1


= 255 = 28-1

• Therefore the range is 0 - 255 (256 numbers)

© 2020 e-Learning Centre, UCSC 23


Signed Magnitude Representation

• Signed Magnitude (Signed binary) numbers

• Have 0 and 1 to represent numbers

• By convention, the leftmost bit is used as the sign bit


• 0 for positive
• 1 for negative

Sign bit

© 2020 e-Learning Centre, UCSC 24


Signed Magnitude (Signed Binary) Numbers

• Signed Magnitude (Signed binary) numbers


• The Smallest positive binary number is
0 0 0 0 0 0 0 0 =0
• The largest positive binary number is
0 1 1 1 1 1 1 1 = 127
• Therefore the range for positive numbers is 0 - 127
(the range is 128 numbers)

© 2020 e-Learning Centre, UCSC 25


Challenges with Negative Numbers in Signed Binary

Problems with simple signed representation


• Two representation of zero: + 0 and – 0
0 0 0 0 0 0 0 0 and 1 0 0 0 0 0 0 0

• Need to consider both sign and magnitude in


arithmetic
• E.g. 5 – 3
= 5 + (-3)
= 00000101+10000011
= 10001000
= -8

© 2020 e-Learning Centre, UCSC 26


Problems with Simple Signed Representation

• Need to consider both sign and magnitude in


arithmetic
E.g. = 18 + (-18)
= 00010010 +10010010
= 10100100
= -36
• We have to change the way these arithmetic
operations are performed based on the signs of two
numbers.

© 2020 e-Learning Centre, UCSC 27


Two’s Complement Number System

• Two's complement is the most common method of


representing signed integers on computers.
• In this scheme most significant bit indicates the sign.
• In order to represent the negative number, the positive
value of the number will be two’s complemented.
Two’s Complement
Bits Unsigned Value
Value
0
000 0 0 -1 1
001 1 1
010 2 2 Two’s
-2 2
011 3 3 Complement
100 4 -4
101 5 -3 -3 3
110 6 -2 -4
111 7 -1
© 2020 e-Learning Centre, UCSC 28
Two’s Complement

• Start from the signed binary representation of its


positive value
• Copy the bit pattern from right to left until a 1 has
been copied
• Complement the remaining bits: all the 1’s with 0’s,
and all the 0’s with 1’s
• Ex. -10510 in Two’s complement (10510 = 0110 10012)
0110 1001 ⟹ 1001 0111
−10510 = 1001 0111
• An exception: 1 0 0 0 0 0 0 0 = -12810

© 2020 e-Learning Centre, UCSC 29


Example: Conversion

• Ex. Convert decimal -104 to two’s complement


• First signed magnitude representation of 104;
10410 = 0110 10002
• Find the first digit1 from right to left
0110 1000
• Copy everything till first digit 1 from right to left
_ _ _ _ 1000
• Then complement the remaining bits
10011000
• Therefore, two’s complement of -10410 is 10011000

© 2020 e-Learning Centre, UCSC 30


Your Turn…!

• What is the SMALLEST and LARGEST signed binary


numbers that can be stored in 1 BYTE ?

© 2020 e-Learning Centre, UCSC 31


Positive

Negative

Source: https://en.wikipedia.org/wiki/Two%27s_complement
© 2020 e-Learning Centre, UCSC 32
Two’s Complement - Benefits

• One representation of zero

• Arithmetic works easily

• Negating is fairly easy

© 2020 e-Learning Centre, UCSC 33


Ranges of Integer Representation

• 8-bit unsigned binary representation


• Largest number: 1 1 1 1 1 1 1 12 = 25510
• Smallest number: 0 0 0 0 0 0 0 02 = 010

• 8-bit two’s complement representation


• Largest number: 0 1 1 1 1 1 1 12 = 12710
• Smallest number: 1 0 0 0 0 0 0 02 = -12810

• The problem of overflow


• 13010 = 1 0 0 0 0 0 1 02
• 0 0 0 0 0 1 02 in two’s complement

© 2020 e-Learning Centre, UCSC 34


Geometric Depiction of Two’s Complement Integers

© 2020 e-Learning Centre, UCSC 35


Integer Data Types in C++

Type Size in Bits Range

unsigned int 16 0 – 65535

int 16 -32768 - 32767

unsigned long int 32 0 to 4,294,967,295

long int 32 -2,147,483,648 to 2,147,483,647

© 2020 e-Learning Centre, UCSC 36


Activities

• Convert following two’s complement numbers to


Decimal representation.
• 0010 1101
• 1101 1010
• 0101 0101
• 1010 1100

© 2020 e-Learning Centre, UCSC 37


Addition with Two’s Complement

• Add 910 to -2310


9 0000 1001
-23 1110 1001
? 1111 0010

• Check whether 1111 0010 represents expected -1410 in


two’s complement representation.

© 2020 e-Learning Centre, UCSC 38


Addition with Two’s Complement

• Add -910 to 2310


Carries 1 111 111
-9 1111 0111
23 0001 0111
? 0000 1110

• The carry going out (encircled) at the sign bit can be


discarded as we are working only with 8 bits.
• Check whether 1111 0010 still represents the expected
1410 in two’s complement representation.

© 2020 e-Learning Centre, UCSC 39


Addition with Two’s Complement

• Add -910 to 2310


Carries 1 111 111
-9 1111 0111
23 0001 0111
? 0000 1110
• We do not consider this as an overflow as it gives the correct
answer.
• An overflow occurs if two positive numbers are added and the
result is negative, or if two negative numbers are added and the
result is positive.
• It is not possible to have overflow when using two's complement
notation if a positive and a negative number are being added
together. 40
© 2020 e-Learning Centre, UCSC
Addition with Two’s Complement

• Add -910 to 2310


Carries 1 111 111
-9 1111 0111
23 0001 0111
? 0000 1110

• Carry going into the sign bit (highlighted in green) is the same as
the carry going out of the sign bit (highlighted in yellow).
• In such a scenario, no overflow occurs.
• When these carries are different, an overflow indicator is set in
the arithmetic logic unit, indicating the result is incorrect.

© 2020 e-Learning Centre, UCSC 41


Overflow in Addition

• Add 12610 to 2310


Carries 0 1111 11
126 0111 1110
23 0001 0111
? 1001 0101

• Carry going into the sign bit (highlighted in green) is 1 and the
carry going out of the sign bit (highlighted in yellow) is 0.
• Addition of two positive numbers has resulted a negative number.
• Carries are different in here and an overflow has occurred.

© 2020 e-Learning Centre, UCSC 42


Carry Vs. Overflow

• CPUs often have flags to indicate both carry and


overflow.
• The overflow flag is used only with signed numbers.
• For unsigned numbers carry flag is sufficient to detect
incorrect outcome after the arithmetic operation.
• However, carry flag is insufficient to detect incorrect
outcome in signed number arithmetic operations.
• When carry going into the sign bit and the carry
going out of the sign bit are different in signed
number arithmetic, then that is an overflow.

© 2020 e-Learning Centre, UCSC 43


Carry Vs. Overflow

Correct
Operation Result Carry ? Overflow ?
Result ?
0100 + 0010 0110 No No Yes
([+4] + [-2] in decimal) (+6 in decimal)

0100 + 0110 1010 No Yes No


([+4] + [+6] in decimal) (-6 in decimal)

1100 + 1110 1010 Yes No Yes


([-4] + [-2] in decimal) (-6 in decimal)

1100 + 1010 0110 Yes Yes No


([-4] + [-6] in decimal) (+6 in decimal)

Carry – indicates there is a carry out from the sign bit

© 2020 e-Learning Centre, UCSC 44


Fractional Numbers in Decimal

• 16.357 = the SUM of ...

7 x 10-3 = 7/1000
5 x 10-2 = 5/100
3 x 10-1 = 3/10
6 x 100 = 6
1 x 101 = 10

357
• 7/1000 + 5/100 + 3/10 + 6 + 10 =16
1000

© 2020 e-Learning Centre, UCSC 45


Fractions in Binary

• 10.011 = the SUM of ...

1 * 2-3 = 1/8
1 * 2-2 = 1/4
0 * 2-1 = 0
0 * 20 = 0
1 * 21 = 2

3
• 1/8 + 1/4 + 2 =2
8
3
• (10.011)2 = 2 in Decimal (Base 10)
8
© 2020 e-Learning Centre, UCSC 46
Activities

• What is Binary 011.0101 in Base 10?

• What is Binary 101.1101 in Base 10?

• What is Binary 111.111 in Base 10?

5
• What is Decimal 3 in Binary ?
16

© 2020 e-Learning Centre, UCSC 47


Scientific Notation in Decimal

• Consider the following representation in decimal


number …
135.26 = .13526 x 103
13526000 = .13526 x 108
0.0000002452 = .2452 x 10-6

• .13526 x 103 has the following components:


• a Mantissa = .13526
• an Exponent = 3
• a Base = 10

© 2020 e-Learning Centre, UCSC 48


Scientific Normalized Notation for Binary Numbers

• Scientific notation for binary. Examples …


• 11011.101 = 1.1011101 x 24
• -10110110000 = -1.011011 x 210
• 0.00000010110111 = 1.0110111 x 2-7

© 2020 e-Learning Centre, UCSC 49


Floating Point Format in 1 Byte

RADIX POINT

MANTISSA
EXPONENT

SIGN

SIGN = 0 (+ve) | 1 (-ve)


EXPONENT in EXCESS FOUR Notation

© 2020 e-Learning Centre, UCSC 50


Floating Point Example

• To STORE the number ...


1
+1 = 1.001 × 20
8
in FLOATING POINT NOTATION ...

1. STORE the SIGN BIT

© 2020 e-Learning Centre, UCSC 51


Floating Point Example

• To STORE the number ...


1
+1 = 1.001 × 20
8
in FLOATING POINT NOTATION ...

2. STORE the MANTISSA BITS

0 0 0 1 0

© 2020 e-Learning Centre, UCSC 52


Floating Point Example

• To STORE the number ...


1
+1 = 1.001 × 20
8
in FLOATING POINT NOTATION ...

3. STORE the EXPONENT BITS

0 X X X 0 0 1 0

© 2020 e-Learning Centre, UCSC 53


Floating Point Example

• To STORE the number ...


1
+1 = 1.001 × 20
8
in FLOATING POINT NOTATION ...

3. STORE the EXPONENT BITS

0 X X X 0 0 1 0

Exponent is represented in Biased representation


© 2020 e-Learning Centre, UCSC 54
Biased (Excess-k) Representation

• EXCESS THREE NOTATION


An excess notation system using bit pattern of length three

Bit Pattern Value Representation


111 4
110 3
101 2
100 1
011 0
010 -1
001 -2
000 -3

© 2020 e-Learning Centre, UCSC 55


Biased (Excess-k) Representation

• Usually, for N bit numbers, k is (2N-1-1)


• E.g. for 4-bit integers, k is 7
for 3-bit integers, k is 3
for 8-bit exponent, k is 127
• The actual value of each bit string is its unsigned value
minus k
• To represent a number in excess-k, add k

© 2020 e-Learning Centre, UCSC 56


Biased (Excess-k) Representation with 4 Bits

Unsigned Excess-k
0000.................... 0 -7
0001.................... 1 -6
0010.................... 2 -5
0011.................... 3 k=7 -4
0100.................... 4 -3
0101.................... 5 -2
0110.................... 6 -1
sliding
0111.................... 7 0
ruler 1000.................... 8 1
1001.................... 9 2
1010.................... 10 3
1011.................... 11 4
1100.................... 12 5
1101.................... 13 6
1110.................... 14 7
1111.................... 15 8
© 2020 e-Learning Centre, UCSC 57
Floating Point Example - Exponent

• To STORE the number ...


1
+1 = 1.001 × 20
8
in FLOATING POINT NOTATION ...

3. STORE the EXPONENT BITS

0 X X X 0 0 1 0

Let’s bring Excess-3 representation for the Exponent


© 2020 e-Learning Centre, UCSC 58
Floating Point Example - Exponent

• To STORE the number ...


1
+1 = 1.001 × 20
8
in FLOATING POINT NOTATION ...

3. STORE the EXPONENT BITS

0 0 1 1 0 0 1 0

Unsigned 0 = 011 in Excess-3


© 2020 e-Learning Centre, UCSC 59
Floating Point Example 2

• To STORE the number ...


1
−3 = −11.01
4
in FLOATING POINT NOTATION ...

- First write the number in standard form

© 2020 e-Learning Centre, UCSC 60


Floating Point Example 2

• To STORE the number ...


1
−3 = −11.01 = −𝟏. 𝟏𝟎𝟏 × 𝟐𝟏
4
in FLOATING POINT NOTATION ...

1. STORE the SIGN BIT

Next, Mantissa…
© 2020 e-Learning Centre, UCSC 61
Floating Point Example 2

• To STORE the number ...


1
−3 = −11.01 = −𝟏. 𝟏𝟎𝟏 × 𝟐𝟏
4
in FLOATING POINT NOTATION ...

2. STORE the MANTISSA BITS

1 1 0 1 0

Next, Exponent…
© 2020 e-Learning Centre, UCSC 62
Floating Point Example 2

• To STORE the number ...


1
−3 = −11.01 = −𝟏. 𝟏𝟎𝟏 × 𝟐𝟏
4
in FLOATING POINT NOTATION ...

2. STORE the EXPONENT BITS

1 1 0 0 1 0 1 0

© 2020 e-Learning Centre, UCSC 63


Activities

• Try to represent following decimal floating-point


numbers in binary representation given below.
• 14.5
• 11/64
• -14.5
5
• −1
8

Sign Bit Exponent Mantissa

© 2020 e-Learning Centre, UCSC 64


Floating Point Binary to Decimal Conversion

1. Convert EXPONENT (EXCESS 4)


2. Apply EXPONENT to MANTISSA
3. Convert BINARY Fraction
4. Apply SIGN

© 2020 e-Learning Centre, UCSC 65


Floating Point Binary to Decimal Conversion

• Example – 10111010 [Assume Exponent = 3 bits,


Mantissa = 4 bits and Exponent in Excess-3 ]
• Sign = 1, Exponent = 011, Mantissa = 1010
• STEP 1: Convert Exponent
• Excess-3 Value = 3
• Real Value = 3 - 3 = 0
• STEP 2: Apply Exponent to Mantissa
• 1.1010 x 20
• STEP 3: Convert Binary Fraction
1 1 5
• 1+ + =1
2 8 8
• STEP 4: Apply sign
5
• −1
8

© 2020 e-Learning Centre, UCSC 66


IEEE Floating Point Standard

• IEEE has introduced standards for FP representations


• The standard is formally known as IEEE-754
• IEEE-754 Single Precision Floating Point

1 bit 8 bits 23 bits


Sign Exponent (Bias 127) Mantissa

• IEEE-754 Double Precision Floating Point


1 bit 11 bits 52 bits
Sign Exponent (Bias 1023) Mantissa

© 2020 e-Learning Centre, UCSC 67


Round Off Error

5
• Try STORE +2 in 8-bit Floating Point Representation
16

𝟓
+𝟐 = 𝟏𝟎. 𝟎𝟏𝟎𝟏 In Binary
𝟏𝟔

© 2020 e-Learning Centre, UCSC 68


Round Off Error

5
• Try STORE +2
16
5
+2 = 10.0101 = 𝟏. 𝟎𝟎𝟏𝟎𝟏 × 𝟐𝟏
16

1. STORE the SIGN BIT

© 2020 e-Learning Centre, UCSC 69


Round Off Error

5
• Try STORE +2
16
5
+2 = 10.0101 = 𝟏. 𝟎𝟎𝟏𝟎𝟏 × 𝟐𝟏
16

2. STORE the MANTISSA

0 0 0 1 0 1

© 2020 e-Learning Centre, UCSC 70


Round Off Error

5
• Try STORE +2
16
5
+2 = 10.0101 = 𝟏. 𝟎𝟎𝟏𝟎𝟏 × 𝟐𝟏
16

2. STORE the MANTISSA

0 0 0 1 0 1

The last bit of Mantissa cannot be stored. DISCARD that bit.

© 2020 e-Learning Centre, UCSC 71


Round Off Error

5
• Try STORE +2
16
5
+2 = 10.0101 = 𝟏. 𝟎𝟎𝟏𝟎𝟏 × 𝟐𝟏
16

3. STORE the EXPONENT

0 1 0 0 0 0 1 0

© 2020 e-Learning Centre, UCSC 72


Round Off Error

5
• Try STORE +2
16
5
+2 = 10.0101 = 𝟏. 𝟎𝟎𝟏𝟎𝟏 × 𝟐𝟏
16

3. STORE the EXPONENT

0 1 0 0 0 0 1 0

Conversion this number back to decimal will not give the


𝟓
original number (+𝟐 )
𝟏𝟔
© 2020 e-Learning Centre, UCSC 73
Round Off Error

5
• Original Value = 2
16
• Stored Value = 01000010 = 𝟏. 𝟎𝟎𝟏𝟎 × 𝟐𝟏
= 10.01
1
=2
4
• Therefore, the Rounding Off Error in this case is
5 1
=2 −2
16 4

1
=
16

© 2020 e-Learning Centre, UCSC 74


Range of Floating Point Representations

In a floating point representation model,


• What is the Largest Positive number ?
• What is the Smallest Positive number ?
• What is the Largest Negative number ?
• What is the Smallest Negative number ?

© 2020 e-Learning Centre, UCSC 75


Range: The Largest Positive Number

• What is the largest positive number ?


• Sign bit should be 0
• Mantissa should be all 1s
• Exponent should be maximum (execess-k)

0 1 1 1 1 1 1 1

= 1.1111 x 24

= 31

© 2020 e-Learning Centre, UCSC 76


Range: The Smallest Positive Number

• What is the largest positive number ?


• Sign bit should be 0
• Mantissa should be all 0s
• Exponent should be minimum (execess-k)

0 0 0 0 0 0 0 0

= 1.0000 x 2-3 = 1/8

= 0.125

© 2020 e-Learning Centre, UCSC 77


Range: The Smallest Negative Number

• What is the largest positive number ?


• Sign bit should be 1
• Mantissa should be all 0s
• Exponent should be minimum (execess-k)

1 0 0 0 0 0 0 0

= -1.0000 x 2-3 = -1/8

= - 0.125

© 2020 e-Learning Centre, UCSC 78


Range: The Largest Negative Number

• What is the largest positive number ?


• Sign bit should be 1
• Mantissa should be all 1s
• Exponent should be maximum (execess-k)

1 1 1 1 1 1 1 1

= -1.1111 x 24

= - 31

© 2020 e-Learning Centre, UCSC 79


Range

• The range of 8 bit floating point representation that


we used can be illustrated as below.

Range Range
- 31 - 0.125 0.125 + 31

© 2020 e-Learning Centre, UCSC 80


Challenge..!

• Try to find the ranges for IEEE-754 single and double


precision representations. (Fill the tables)

• IEEE-754 Single Precision


Negative Min Negative Max Positive Min Positive Max

• IEEE-754 Double Precision


Negative Min Negative Max Positive Min Positive Max

© 2020 e-Learning Centre, UCSC 81


Special Cases: Zero

• Zero cannot be represented with this format of FP as


we assume there is always 1 immediate left of the
radix point.
• Therefore, IEEE-754 defines all 0s in mantissa and
exponent denote zero.
• Both cases are regarded as standard for 0
0 0000 0000 000 0000 0000 0000 0000 0000

1 0000 0000 000 0000 0000 0000 0000 0000

© 2020 e-Learning Centre, UCSC 82


Special Cases: Infinity and NaN

• Infinity is denoted by all 1s in exponent with all 0s in


mantissa.
+ Infinity 0 1111 1111 000 0000 0000 0000 0000 0000

- Infinity 1 1111 1111 000 0000 0000 0000 0000 0000

• Not a Number (NaN) is denoted by all 1s in exponent


with any non-zero value in mantissa. Sign bit has no
meaning in this situation.

1 1111 1111 Any Non-zero Value

© 2020 e-Learning Centre, UCSC 83


Special Cases: Denormalized Numbers

• IEEE-754 assumes that all FP numbers are normalized


(there is always single digit at the immediate left to
radix point and that digit is 1. Ex. 1.0101 x 2-3)
• However, IEEE-754 allows denormalized representation
• When exponent is all 0s and mantissa is non-zero, it is
assumed the number is in denormalized form.
• Ex. 1 0000 0000 Any Non-zero Value

Here, exponent is in excess-127 form. Hence the true value of


exponent is -127

© 2020 e-Learning Centre, UCSC 84


Range for IEEE-754

• Max: 1.111 1111 1111 1111 1111 1111 x 2127


• Even though 2128 can be represented, it will make
all 1s in exponent, which is the NaN
• Min: 0. 000 0000 0000 0000 0001 x 2-127
• Since the exponent is -127 which is converted to all
0s with Excess-127 notation, the value represented
will be regarded as denormalized number. Hence,
there is no 1 left to the radix point.

© 2020 e-Learning Centre, UCSC 85


Range for IEEE-754

• With the sign(+ or -), these Min and Max help to


define the -Min, -Max and +Min, +Max respectively.

Negative Positive
Overflow Overflow
0

Range Range
- Max - Min + Min + Max

Negative Positive
Underflow Underflow

© 2020 e-Learning Centre, UCSC 86


Problems with Floating Point Numbers

• Out of range: Overflow and Underflow


• Within the range: Rounding off error
• Floating point arthmetic is not always associative
•Ex. There can be instances where three FP numbers
𝑎, 𝑏 and 𝑐, that
• 𝑎 + 𝑏 + 𝑐 ≠ 𝑎 + (𝑏 + 𝑐)
• There can be instance where the FP arithmetic is not
distributive.
• Ex. a × 𝑏 + 𝑐 ≠ 𝑎𝑏 + 𝑎𝑐

© 2020 e-Learning Centre, UCSC 87


Character Codes

• Character encoding is the process of assigning


numbers to graphical characters that gives the
meaning to its representation.
• Character codes have evolved from basic coding
systems such Binary Coded Decimal to Unicode
• Some of the Coding Systems
• EBCDIC
• ASCII
• Unicode

© 2020 e-Learning Centre, UCSC 88


EBCDIC

• EBCDIC stands for Extended Binary Coded Decimal


Interchange Code.
• 8-bit Binary Coded Decimal representation.
• Characters are represented by appending digit bits to
zone bits (see the figure in the next slide).
• Character A = 1100 0001
• Character a = 1000 0001

© 2020 e-Learning Centre, UCSC 89


EBCDIC Code

© 2020 e-Learning Centre, UCSC 90


EBCDIC Code Abbreviations

© 2020 e-Learning Centre, UCSC 91


ASCII

• American Standard Code for Information Interchange


(ASCII)
• Use bit patterns of length seven to represent
•Letters of English alphabet: a - z and A - Z
•Digits: 0 – 9
•Punctuation symbols: (, ), [, ], {, }, ’, ”, !, /, \
•Arithmetic Operation symbols: +, -, *, <, >, =
•Special symbols: (space), %, $, #, &, @, ^
• 27 = 128 characters can be represented by ASCII

© 2020 e-Learning Centre, UCSC 92


Character Representation: ASCII Table

Symbol ASCII Symbol ASCII Symbol ASCII Symbol ASCII

(space) 00100000 A 01000001 a 01100001 0 00110000

! 00100001 B 01000010 b 01100010 1 00110001

“ 00100010 C 01000011 c 01100011 2 00110010

# 00100011 D 01000100 d 01100100 3 00110011

$ 00100100 E 01000101 e 01100101 4 00110100

% 00100101 F 01000110 f 01100110 5 00110101

& 00100110 G 01000111 g 01100111 6 00110110

……. …….. ……. …….


© 2020 e-Learning Centre, UCSC 93
Character Representation: ASCII Table

© 2020 e-Learning Centre, UCSC 94


Character Representation: Unicode

• EBCDIC and ASCII are built around the Latin alphabet


• Are restricted in their ability for representing non-
Latin alphabet
• Countries developed their own codes for native
languages

• Unicode: 16-bit system that can encode the characters


of most languages

• 16 bits = 216 = 65,636 characters

© 2020 e-Learning Centre, UCSC 95


Character Representation: Unicode

• The Java programming language and some operating


systems now use Unicode as their default character
code

• Unicode code space is divided into six parts


• The first part is for Western alphabet codes,
including English, Greek, and Russian

• Downward compatible with ASCII and Latin-1


character sets

© 2020 e-Learning Centre, UCSC 96


Character Representation: Example

• English section of Unicode Table


• ACSII equivalent of A is 4116
• Unicode is equivalent of A: 00 4116

Full chart list:


http://www.unicode.org/charts/

© 2020 e-Learning Centre, UCSC 97


Sinhala Unicode

E.g. Unicode for Sinhala language’s character අ is 0D85


Sinhala Unicode Chart: https://unicode.org/charts/PDF/U0D80.pdf

© 2020 e-Learning Centre, UCSC 98


Tamil Unicode

E.g. Unicode for Tamil language’s character அ is 0B85


Sinhala Unicode Chart: https://unicode.org/charts/PDF/U0B80.pdf

© 2020 e-Learning Centre, UCSC 99


Thank you..!

10
© 2020 e-Learning Centre, UCSC
0

You might also like