Title: Number Representation
1Lecture 3
2Decimal and Binary
- Decimal system
- It is basically intuitive. The power of the base
of system, which in decimal is 10. - The first position is ,
- the second position is ,
- and the third position is .
3Decimal and Binary
- 243 3 x 4 x 2 x ,
- it is very intuitional.
- Decimal system
4Decimal and Binary
- Binary system
- Whereas the decimal system is based on 10,
the binary system is based on 2. - In position table, each position is double the
previous position. Again, this is because the
base of the system is 2.
5Decimal and Binary
- Why is
- 243 1 x 1 1 x 2 0 x 4 0 x 8 1 x 16
- 1 x 32 1 x 64 1 x 128 ?
- Binary system
6Conversions
- The integer and fraction portions of the number
are handled separately. - Radix divide technique convert the integer
portion. - Radix multiply technique convert the fraction
portion.
7Conversions
- Radix divide technique
- Divide the given integer successively by the
required radix, noting the remainder at each
step. - The quotient at each step becomes the new
dividend for subsequent division.
8Conversions
- Stop the division process when the quotient
becomes zero. - Collect the remainders from each step (last to
first) and place them left to right to form the
required number.
9Conversions
- Integers
- Binary to decimal conversion
- Since each binary bit can be only 0 or 1,
the - result will be either 0 or the value of
the weight. - After multiplying all the digits, add the
results. -
10Conversions
- 1x 0x 1x 1x 0x 1x
- 1x1 0x2 1x4 1x8 0x16 1x32
- 45
- Binary to decimal conversion
11Conversions
- Decimal to binary conversion
- To convert from decimal to binary, use
repetitive division. - Decimal to binary conversion
12Conversions
-
- Decimal to binary conversion
13Conversions
- Decimal to Octal conversion
-
14Conversions
15Conversions
- Radix multiply technique
- Successively multiply the given fraction by the
required base, noting the integer portion of the
product at each step. - Use the fractional part of the product as the
multiplicand for subsequent steps.
16Conversions
- Stop when the fraction either reaches 0 or
recurs. - Collect the integer digits at each step from
first to last and arrange them left to right.
Decimal to binary conversion
17Conversions
- Fraction
- Decimal to binary conversion
-
-
18Conversions
- Decimal to Octal and Decimal to Hexadecimal
-
19Conversions
20Integer representation
- An integer can be positive or negative.
- A negative integer ranges from negative infinity
to 0 a positive integer ranges from 0 to
positive infinity. - Range of integers
21Integer representation
- However, no computer can store all the integers
in the range. To do so would require an infinite
number of bits, which means a computer with
infinite storage capability. - To use computer memory more efficiently, two
broad categories of integer representation have
been developed - unsigned integers
- signed integers.
22Integer representation
- Signed integers may also be represented in three
distinct ways - Taxonomy of integers
23Integer representation
- Unsigned integers format
- An unsigned integer is an integer without a sign.
Its range is between 0 and positive infinity.
24Integer representation
- The following defines the range of unsigned
integers in a computer, where N is the number of
bits allocated to represent one unsigned integer
-
- Range 0 ( -1 )
- shows two common ranges for computers today.
25Integer representation
- Representation
- Storing unsigned integers is a straightforward
process as outlined in the following steps - The number is changed to binary.
- 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.
26Integer representation
- unsigned integers are stored in two different
computers - 8-bit allocation
- 16-bit allocation.
- Note that decimal 258 and decimal 24,760 cannot
be stored in a computer using 8-bit allocation
for an unsigned integer.
27Integer representation
- Decimal 1,245,678 cannot be stored in either of
these computers. - The condition called overflow occurs
- Storing unsigned integers in two different
computer
28Integer representation
- Overflow
- If you try to store an unsigned integer such as
256 in an 8-bit memory location, you get a
condition called overflow.
8-bit
29Integer representation
- Applications
- Counting When you count, you do not need
negative numbers. You start counting from 1
(sometimes 0) and go up. - Addressing Some computer languages store the
address of a memory location inside memory
location. Addresses are positive numbers starting
from 0.
30Integer representation
- Sign-and-magnitude format
- The following defines the range of sign-and
-magnitude integers in a computer, where N is the
number of bits allocated to represent one
sign-and -magnitude integer - Range - ( -1 ) ( -1 )
31Integer representation
- There two 0s in sign-and-magnitude
representation - 0 ? 00000000
- -0 ? 10000000
-
Range of sign-and-magnitude integer
32Integer representation
- Representation
- Storing sign-and-magnitude integers is a
straightforward process - The number is changed to binary the sign is
ignored. - If the number of bits is less than N -1, 0s are
added to the left of number so that here is a
total of N-1 bits.
33Integer 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. - Ex. 8 bit
- Range 127 -127
34Integer representation
- Interpretation
- How do you interpret a sign-and-magnitude binary
representation in decimal? - Ignore the first (leftmost) bit.
- Change the N-1 bits from binary to decimal
- Attach a or a sign to the number based on the
leftmost bit. - EX.
10010101 represents -21 01111111 represents
127
35Integer representation
- Ones complement format
- The range of ones complement integers in a
computer, where N is the number of bits allocated
to represent a ones complement integer - Range - ( -1 ) ( -1 )
36Integer representation
- There two 0s in ones complement representation
- 0 ? 00000000
- -0 ? 11111111
Range of ones complement integer
37Integer representation
- Representation
- Sorting ones complement integers requires the
following steps - The number is changed to binary the sign is
ignored. - 0s are added to the left of the number to make a
total of N bits.
38Integer representation
- If the sign is positive, no more action is
needed. If the sign is negative, every bit is
completed (changed from 0 to 1 or from 1 to 0). - Ex. 8 bit
- Decimal Binary number 1s complement
- 1 ? 00000001 ? 00000001
- 2 ? 00000010 ? 00000010
- -1 ? 00000001 ? 11111110
- -2 ? 00000010 ? 11111101
-
- (ignore sign)
39Integer representation
- In ones 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. - Decimal 1s complement Decimal 1s
complement
40Integer representation
- Twos complement format
- Twos complement is most common, the most
important, and the most widely used
representation of integers today. - The range of twos complement integers in a
computer, where N is the number of bits allocated
for a twos complement integer - Range - ( ) ( -1 )
41Integer representation
- Note that in this system,there is only one 0 and
that the beginning of the range is 1 less than
that of ones complement. - 0 and -0 ? 00000000
Range of twos complement integer
42Integer representation
- Representation
- Storing twos complement requires the following
steps - The number is changed to binary the sign is
ignored. - If the number of bits is less than N, 0s are
added to the left of the number so that there is
a total of N bits.
43Integer representation
- 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. - Ex. 8 bit
- Decimal Binary number 2s complement
- 1 ? 00000001 ? 00000001
- 2 ? 00000010 ? 00000010
- -1 ? 00000001 ? 11111111
- -2 ? 00000010 ? 11111110
- (ignore sign)
44Integer representation
Summary of integer representation
45Floating-point representation
- Floating point
- Floating-point is a system of arithmetic in which
the decimal (or other radix) point is allowed to
float as computations are performed. -
46Floating-point representation
- Normalization
- There is a standard representation for
floating-point numbers. It is normalization, the
moving of the decimal point so that there is only
one digit to the left of the decimal point. - Ex.
- 245.17 2.4517 x
- x
-
47Floating-point representation
- IEEE standard
- The Institute of Electrical and Electronic
Engineers (IEEE) has defined three standards for
floating-point numbers two are used to store
numbers in memory (single precision).
48Floating-point representation
- Single-precision
- It is a computer numbering format that occupies
one storage location in computer memory at a
given address. - Note that the number inside the boxes
- is the number of bits for each field.
49Floating-point representation
- Single-precision representation
- The procedure for storing a normalized
floating-point number in memory using
single-precision format is as follows - Store the sign as 0 (positive) or 1(negative).
- Store the exponent (power of 2) as Excess 127.
- Store the mantissa as an unsigned integer.
50Floating-point representation
- Ex. 111.000011 - x 1.11000011
- Step 1 - ? Sign 1
- Step 2 Exponent 2 127
- Step 3 0.11000011
- ? Mantissa 11000011000000000000000
51Floating-point representation
- Double precision
- It is a computer numbering format that occupies
two storage locations in computer memory at
address and address1. - Note that the number inside the boxes
- is the number of bits for each field.
52Floating-point representation
- Double-precision representation
- The procedure for storing a normalized
floating-point number in memory using
single-precision format is as follows - Store the sign as 0 (positive) or 1(negative).
- Store the exponent (power of 2) as Excess_1023.
- Store the mantissa as an unsigned integer.
53Floating-point representation
- Ex. -0.75 - -1.1 x
- Step 1 - ? Sign 1
- Step 2 Exponent -1 1023
-
- Step 3 0.1
- ? Mantissa 1000000000
- 52 bits
-
54Addition
- One's complement arithmeticthe carry generated
from the sign bit is added to the LSB of the
result to complete the addition. - Ex.
55Addition
56Addition
- Two's complement arithmetic
- EX.
- Here the sign-magnitude and twos complement
representations are the same, since both numbers
are positive.
57Addition
- Here the negative number is represented in the
- complement form.
- The sign bits are also included in the addition
process. - There is a carry from the sign bit position,
which is ignored.
58Addition
- no carry is generated from the MSB during the
addition. - the result is negative since the sign bit is 1.
- the result is in the complement form and must be
complemented to obtain the sign-magnitude
representation.
59Addition