Chapt 3 Number Representation

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 93

Chapter 3

Number
Representation
OBJECTIVES
After learning this chapter, the reader should be able
to :Convert a number from decimal 、 hexadecimal,octal to
binary notation and vice versa.
Understand the different representations of an integer inside
a computer: unsigned, sign-and-magnitude, one’s complement,
and two’s complement.

Understand the Excess system that is used to store the


exponential part of a floating-point number.
Understand how floating numbers are stored inside a computer
using the exponent and the mantissa.
Contents
3.1 Decimal and Binary
3.2 Conversion
3.3 Hexadecimal
3.4 Octal
3.5 Integer representation
3.6 Excess System
3.7 Floating-Point Representation
3.1
DECIMAL
AND
BINARY
Figure 3-1
Decimal system

basis 243=2×102+4 × 101+3 × 100

position value:weight
Figure 3-2
Binary system

(11110011)2=1×27+1 ×26+1 × 25 + 1×24+1 ×21+1 × 20


3.2

CONVERSION
Figure 3-3
Binary to decimal conversion
Example 1
Convert the binary number 10011 to decimal.
Solution
Write out the bits and their weights. Multiply the bit by
its corresponding weight and record the result. At the
end, add the results to get the decimal number.
Binary 1 0 0 1 1
Weights 16 8 4 2 1
-------------------------------------
16 + 0 + 0 + 2 + 1
Decimal 19
Convert the binary number 1001.101 to decimal.
Solution

(1001.101)2
=1×23+0×22+0×21+1×20+1×2-1
+0×2-2+1×2-3
=8+1+0.5+0.125
=(9.625)10
Example 2
Convert the decimal number 35 to binary.
Solution
Write out the number at the right corner. Divide the
number continuously by 2 and write the quotient and the
remainder. The quotients move to the left, and the
remainder is recorded under each quotient. Stop when
the quotient is zero.
0  1  2  4  8  17  35 Dec.
Binary 1 0 0 0 1 1
Figure 3-4
Decimal to binary conversion
3.3

HEXADECIMAL
NOTATION
Note:

A 4-bit pattern can be represented


by a hexadecimal digit,
and vice versa.
Table 2.2 Hexadecimal digits

Bit Hex Bit Hex


Pattern Digit Pattern Digit
------------ ------------ ------------ ------------
0000 0 1000 8
0001 1 1001 9
0010 2 1010 A
0011 3 1011 B
0100 4 1100 C
0101 5 1101 D
0110 6 1110 E
0111 7 1111 F
Figure 2-10
Binary to hexadecimal and
hexadecimal to binary transformation
Example 1

Show the hexadecimal equivalent of the bit


pattern 1100 1110 0010.

Solution

Each group of 4 bits is translated to


one hexadecimal digit. The equivalent
is xCE2.
Example 2

Show the hexadecimal equivalent of the bit


pattern 0011100010.

Solution

Divide the bit pattern into 4-bit groups (from the


right). In this case, add two extra 0s at the left to
make the number of bits divisible by 4. So you
have 000011100010, which is translated to
x0E2.
Example 3

What is the bit pattern for x24C?

Solution

Write each hexadecimal digit as its


equivalent bit pattern to get
001001001100.
Example ?

Show the hexadecimal equivalent of the bit


pattern ( 11000011.10101)2 .

Solution

1100 0011. 1010 1000


C 3. A 8
(11000011.10101)2=(C3.A8)16
Example ?
What is the bit pattern for ( 8B.C4)16?
Solution

8 B. C 4
1000 1011. 1100 0100

(8B.C4)16 = (10001011.110001)2
3.4
OCTAL
NOTATION
Note:

A 3-bit pattern can be represented


by an octal digit, and vice versa.
Table 3.3 Octal digits

Bit Oct Bit Oct


Pattern Digit Pattern Digit
----------- ----------- ----------- -----------
- - - -
000 0 100 4
001 1 101 5
010 2 110 6
011 3 111 7
Figure 2-11
Binary to octal and
octal to binary transformation
Example 4

Show the octal equivalent of the bit pattern


101110010.

Solution

Each group of 3 bits is translated to


one octal digit. The equivalent is 0562,
o562, or 5628.
Example 5

Show the octal equivalent of the bit pattern


1100010.

Solution

Divide the bit pattern into 3-bit groups (from the


right). In this case, add two extra 0s at the left to
make the number of bits divisible by 3. So you
have 001100010, which is translated to 1428.
Example 6

What is the bit pattern for 248?

Solution

Write each octal digit as its equivalent


bit pattern to get 010100.
Example ?

Show the octal equivalent of the bit pattern


(11110100.1110111)2 .

Solution

011 110 100 . 111 011 100


3 6 4 . 7 3 4
(11110100.1110111)2=(364.734)8
Example ?
What is the bit pattern for ( 351.65 ) 8 ?
Solution

3 5 1. 6 5
011 101 001. 110 101

(351.65)8 = (11101001.110101)2
3.5
INTEGER
REPRESENTATION
Figure 3-5
Range of integers

negative integer positive integer


Figure 3-6
Taxonomy of integers
Unsigned Integers Format

Most computers define a constant called the


maximum unsigned integer.

Ranger: 0~ (2N-1)

Table 3.1 Range of unsigned integers


Number of Bits Range
-------------------------------------
--------- 0 255
8 0 65,535
16
Unsigned Integers Format

Representation:
1.The number is changed to binary;
2.if the number of bits is less than N, 0s are
added to the left of the binary number so
that there is a total of N bits.
Example 3

Store 7 in an 8-bit memory location.

Solution

First change the number to binary 111.


Add five 0s to make a total of N (8) bits,
00000111. The number is stored in the
memory location.
Example 4

Store 258 in a 16-bit memory location.

Solution

First change the number to binary


100000010. Add seven 0s to make a total of
N (16) bits, 0000000100000010. The
number is stored in the memory location.
Table 3.2 Example of storing unsigned integers in
two different computers

Decimal 8-bit allocation 16-bit allocation


----------- ------------ ---------------------------
7 00000111 0000000000000111
234 11101010 0000000011101010
258 overflow 0000000100000010
24,760 overflow 0110000010111000
1,245,678 overflow overflow
Example 5

Interpret 00101011 in decimal if the number


was stored as an unsigned integer.

Solution

the number in decimal is 43.


Unsigned Integers Format

Application:
1.Counting;
2.Addressing.
Sign-and-magnitude Format

We need 1 bit to represent the sign(0 for


positive, 1 for negative).
The maximum positive value is one half
the unsigned value.

Ranger: -(2 N-1-1)~ +(2N-1-1)


Note:

There are two 0s in sign-and-magnitude


representation: positive and negative.

In an 8-bit allocation:
+0  00000000
-0  10000000
Table 3.3 Range of sign-and-magnitude integers

# of Bits Range
---------- -------------------------------------------------------
8 127 0 +0 +127
16 32767 0 +0 +32767
32  0 +0 +2,147,483,647
Sign-and-magnitude Format

Representation:
1.The number is changed to binary;the sign is
ignored
2.if the number of bits is less than N-1, 0s are
added to the left of the binary number so that
there is a total of N-1 bits.
3.If the number is positive, o is added to the
left. If the number is negative, 1 is added to
the left.
Note:

In sign-and-magnitude representation,
the leftmost bit defines the sign of the
number. If it is 0, the number is
positive.If it is 1, the number is negative.
Example 6
Store +7 in an 8-bit memory location using
sign-and-magnitude representation.
Solution
First change the number to binary 111. Add
four 0s to make a total of N-1 (7) bits, 0000111.
Add an extra zero because the number is
positive. The result is:
00000111
Example 7

Store –258 in a 16-bit memory location


using sign-and-magnitude representation.
Solution
First change the number to binary 100000010.
Add six 0s to make a total of N-1 (15) bits,
000000100000010. Add an extra 1 because the
number is negative. The result is:
1000000100000010
Table 3.4 Example of storing sign-and-magnitude integers
in two computers

Decimal 8-bit allocation 16-bit allocation


----------- ------------ ---------------------------
+7 00000111 0000000000000111
-124 11111100 1000000001111100
+258 overflow 0000000100000010
-24,760 overflow 1110000010111000
Sign-and-magnitude Format

Interpretation:
1.Ignore the first bit.
2.Change the N-1 bits form binary to decimal
as shown at the beginning of the chapter..
3.Attach a + or a – sign to the number based
on the leftmost bit..
Example 8

Interpret 10111011 in decimal if the number


was stored as a sign-and-magnitude integer.

Solution

Ignoring the leftmost bit, the remaining


bits are 0111011. This number in decimal
is 59. The leftmost bit is 1, so the number is
–59.
One’s Complement Format

To represent a positive number, use the


convention adopted for an unsigned integer.
To represent a negative number, complement
the positive number.

Ranger: -(2 N-1-1)~ +(2N-1-1)


Note:

There are two 0s in one’s complement


representation: positive and negative.
In an 8-bit allocation:
+0  00000000
-0  11111111
Table 3.5 Range of one’s complement integers

# of Bits Range
--------- -------------------------------------------------------
8 127 0 +0 +127
16 32767 0 +0 +32767
32  0 +0 +2,147,483,647
One’s Complement Format

Representation:
1.The number is changed to binary;the sign is
ignored
2.0s are added to the left of the number to
make a total of N bits.
3.If the sign is positive, no more action is
needed. If the sign is negative, every bit is
complemented(changed form 0 to 1 and 1 to
0).
Note:

In one’s complement representation,


the leftmost bit defines the sign of the
number. If it is 0, the number is
positive.If it is 1, the number is negative.
Example 9

Store +7 in an 8-bit memory location using


one’s complement representation.
Solution
First change the number to binary 111. Add five
0s to make a total of N (8) bits, 00000111. The
sign is positive, so no more action is needed. The
result is:
00000111
Example 10

Store –258 in a 16-bit memory location


using one’s complement representation.
Solution
First change the number to binary 100000010.
Add seven 0s to make a total of N (16) bits,
0000000100000010. The sign is negative, so
each bit is complemented. The result is:
1111111011111101
Table 3.6 Example of storing one’s complement integers in
two different computers

Decimal 8-bit allocation 16-bit allocation


---------- ------------ ---------------------------
 00000111 0000000000000111
 11111000 1111111111111000
 01111100 0000000001111100
 10000011 1111111110000011
 overflow 0110000010111000
 overflow 1001111101000111
One’s Complement Format

Interpretation
1.If the leftmost bit is 0
a.Change the entire number from binary to
decimal.
b.Put a + in front of the number.
2. If the leftmost bit is 1
a.Complement the entire number .
b.Change the entire number from binary to
decimal.
c.Put a - in front of the number.
Example 11

Interpret 11110110 in decimal if the number


was stored as a one’s complement integer.
Solution

The leftmost bit is 1, so the number is negative.


First complement it . The result is 00001001.
The complement in decimal is 9. So the original
number was –9.
Note:

One’s complement means reversing all


bits. If you one’s complement a positive
number, you get the corresponding
negative number. If you one’s
complement a negative number, you get
the corresponding positive number. If
you one’s complement a number twice,
you get the original number.
Two’s Complement Format

Note:

Two’s complement is the most common,


the most important, and the most widely
used representation of integers today.

Ranger: -(2 N-1)~ +(2N-1-1)


Table 3.7 Range of two’s complement integers

# of Bits Range
--------- -------------------------------------------------------
8 128  0 +127
16 32,768 0 +32,767
32  0 +2,147,483,647
Two’s Complement Format

Representation:
1.The number is changed to binary;the sign is
ignored
2.0s are added to the left of the number to
make a total of N bits.
3.If the sign is positive, no more action is
needed. If the sign is negative, leave all the
rightmost 0s and the first 1 unchanged.
Complement the rest of the bits.
Note:

In two’s complement representation,


the leftmost bit defines the sign of the
number. If it is 0, the number is positive.
If it is 1, the number is negative.
Example 12

Store +7 in an 8-bit memory location using


two’s complement representation.
Solution
First change the number to binary 111. Add five
0s to make a total of N (8) bits, 00000111.The
sign is positive, so no more action is needed. The
result is:
00000111
Example 13
Store –40 in a 16-bit memory location using two’s
complement representation.
Solution
First change the number to binary 101000. Add
ten 0s to make a total of N (16) bits,
0000000000101000. The sign is negative, so
leave the rightmost 0s up to the first 1 (including
the 1) unchanged and complement the rest. The
result is:
1111111111011000
Table 3.8 Example of storing two’s complement integers in
two different computers

Decimal 8-bit allocation 16-bit allocation


----------- ------------ ---------------------------
 00000111 0000000000000111
 11111001 1111111111111001
 01111100 0000000001111100
 10000100 1111111110000100
 overflow 0110000010111000
 overflow 1001111101001000
Note:

There is only one 0 in two’s complement:


In an 8-bit allocation:
0  00000000
Two’s Complement Format
Interpretation
1.If the leftmost bit is 0,Change the entire
number from binary to decimal,Put a + in
front of the number.
2. If the leftmost bit is 1
a.Leave the rightmost bits up to the first
1(inclusive) unchanged. Complement the rest
of the bits.
b.Change the whole number from binary to
decimal.
c.Put a - in front of the number.
Example 14

Interpret 11110110 in decimal if the number


was stored as a two’s complement integer.
Solution

The leftmost bit is 1. The number is negative.


Leave 10 at the right alone and complement the
rest. The result is 00001010. The two’s
complement number is 10. So the original
number was –10.
Note:

Two’s complement can be achieved by


reversing all bits except the rightmost bits up to
the first 1 (inclusive). If you two’s complement
a positive number, you get the corresponding
negative number. If you two’s complement a
negative number, you get the corresponding
positive number. If you two’s complement a
number twice, you get the original number.
Table 3.9 Summary of integer representation
Contents Unsigned Sign-and- One’s Two’s
of Memory Magnitude Complement Complement
0000 0   
0001 1   
0010 2   
0011 3   
0100 4   
0101 5   
0110 6   
0111 7   
1000 8   
1001 9   
1010 10   
1011 11   
1100 12   
1101 13   
1110 14   
1111 15   
3.6
EXCESS
SYSTEM
Excess System

Representation
1.Add the magic number to the integer.

2.Change the result to binary and add 0s so


that there is a total of N bits.
Interpretation
1.Change the number to decimal;
2.Subtract the magic number from the
integer.
Example 15

Represent –25 in Excess_127 using an 8-bit


allocation.
Solution

First add 127 to get 102. This number in


binary is 1100110. Add one bit to make it 8
bits in length. The representation is
01100110.
Example 16

Interpret 11111110 if the representation is


Excess_127.

Solution

First change the number to decimal. It


is 254. Then subtract 127 from the
number. The result is decimal 127.
3.7
FLOATING-POINT
REPRESENTATION
Floating-Point representation

To represent a floating-point
number(a number containing an integer
and a fraction),the number is divided
into two parts:the integer and the
fraction.

For example:
A Floating-point number 14.234
Integer:14
Fraction:0.234
Floating-Point representation

To convert a floating-point number to


binary:
1.Convert the integer part to binary.

2.Convert the fraction to binary.

3.Put a decimal point between the two parts.


Figure 3-7
Changing fractions to binary
Example 17
Transform the fraction 0.875 to binary
Solution
Write the fraction at the left corner. Multiply the
number continuously by 2 and extract the
integer part as the binary digit. Stop when the
number is 0.0.
0.875  1.750  1.5  1.0  0.0
0 . 1 1 1
Example 18
Transform the fraction 0.4 to a binary of 6 bits.
Solution
Write the fraction at the left cornet. Multiply the
number continuously by 2 and extract the
integer part as the binary digit. You can never
get the exact binary representation. Stop when
you have 6 bits.

0.4  0.8  1.6  1.2  0.4  0.8  1.6


0 . 0 1 1 0 0 1
Normalization

To present the number 1101.1101(13.812


5)
2 × 1.1011101
3
or
2 × .011011101
5
or
2-4× 11011101.
Note

Normalization:Moving the decimal point


so that there is only one 1 to the left of
the decimal point.
Table 3.10 Example of normalization

Original Number Move Normalized


------------ ------------ ------------
 6 x
 2 x
 6 x
 3 x

E
N  ()2 S
Sign,Exponent and Mantissa

For example:
A number +1000111.0101 is Normalized, it
becomes,
+ 2 6
× 1.0001110101
sign + exponent 6 mantissa 0001110101
Sign,Exponent and Mantissa

Sign:The sign of the number can be stored


using 1bit(0 or 1).
Exponent:The exponent defines the
movement of the decimal point. Note that
the power can be negative of positive.
EXCESS representation is the method
used to store the exponent.
Mantissa:is the binary number to the right
of the decimal point. It defines the
precision of the number. It is stored as an
unsigned integer.
Figure 3-8

IEEE standards for floating-point representation


Single-precision Representation

1. Store the sign as 0 (positive) or 1


(negative).
2.Store the exponent as Excess_127.
3.Store the mantissa as an unsigned
integer.
Example 19

Show the representation of the normalized


number + 26 × 1.01000111001
Solution
The sign is positive. The Excess_127 representation of
the exponent is 133. You add extra 0s on the right to
make it 23 bits. The number in memory is stored as:

0 10000101 01000111001000000000000
sign exponent mantissa
Table 3.11 Example of floating-point representation

Number Sign Exponent Mantissa


------------ ---- ----------- -------------------------------
-2 x 1.11000011
2 1 10000001 11000011000000000000000
+2-6 x 1.11001 0 01111001 11001000000000000000000
-2-3 x 1.110011 1 01111100 11001100000000000000000
Floating-Point Interpretation for Single precision

1. Use the leftmost bit as the sign.


2.Change the next 8 bits to decimal and
subtract 127 from it. This is the exponent.
3.Add 1 and a decimal point to the next 23
bits. You can ignore any extra 0s at the
right.
4.Move the decimal point to the correct
position using the value of the exponent.
5. Change the whole part to decimal.
6.Change the fraction part to decimal.
7.Combine the whole and the fraction part.
Example 20

Interpret the following 32-bit floating-point


number
1 01111100 11001100000000000000000
Solution
The sign is negative. The exponent is –3 (124 –
127). The number after normalization is
-2-3 × 1.110011

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