L12 Representation of Numbers
L12 Representation of Numbers
Number Representation
Representation of Integers
➢ For purposes of storage and processing, computer uses
strings of binary digits to represent all forms of
information, including numbers. No special symbols are
available for the minus sign and radix point.
• Only binary digits (0 and 1) may be used to represent
numbers, positive/ negative, large and small.
➢ If we are limited to nonnegative integers
• 8-bit word can represent the numbers from 0 to 255
➢ If we are to include negative numbers as well, there are
different conventions such as
• Sign-Magnitude representation
• 1’s complement representation
• 2’s complement representation
• Biased Representation
Representation of Integers
➢ Sign and Magnitude
• The simplest form of representation employs
the MSB as a sign bit
• If the sign bit is 0, the number is positive; if the
sign bit is 1, the number is negative.
• In an n-bit word, the rightmost (n – 1) bits hold
the magnitude of the integer.
• Example:
• Disadvantages:
o Addition and subtraction become complex
o Two representations of 0
Representation of Integers
➢ 1’s complement
▪ 1’s complement representation also uses the MSB as
a sign bit – making it easy to test whether an integer
is positive or negative
▪ Negative of a number is obtained by inverting all of
the bits of the positive binary value
▪ Range of values: –(2^(n – 1) – 1) to +(2^(n – 1) – 1)
▪ Example:
+18 = 00010010
– 18 = 11101101
▪ Addition and subtraction is simple addition of two
binary numbers
▪ Disadvantage:
▪ Two representation for zero: 00000000 is +0 and
11111111 is –0
Representation of Integers
➢ 2’s complement
▪ 2’s complement representation also uses the
MSB as a sign bit – making it easy to test whether
an integer is positive or negative
▪ Negative of a number is obtained by inverting all
of the bits of the positive binary value and adding
a 1 to the result
▪ Range of values: –(2^(n – 1)) to +(2^(n – 1) – 1)
▪ Example:
+18 = 00010010
- 18 = 11101110
▪ Addition and subtraction is simple addition of
two binary numbers
▪ One representation for zero: 00000000
Representation of Integers
▪ Most computer integer representations of computer uses
2’s complement
▪ Other signed integer representations may be used -
• Biased representation: add a bias value to the number
and represent using the corresponding binary
equivalent
▪ Fixed Point Representation
• Above mentioned representation are called fixed point
representations because the radix point is assumed to
have fixed position – right of the rightmost digit (LSB)
Integer Arithmetic – 2’s Complement
Negation
Take the Boolean complement of each bit of the integer, add 1
to the result
➢ Trade offs
▪ Numbers represented in floating-point notation are not
spaced evenly along the number line, unlike fixed-point
numbers
▪ Range determines maximum and minimum number of
values that can be represented
▪ Precision determines the minimum fractional value that
can be represented accurately
▪ Trade-off between range and precision:
• more number of bits in significand => more precision
• more number of bits in exponent => greater range
Floating Point – IEEE Standard