A Is The Most Basic Unit of Information in A Computer
A Is The Most Basic Unit of Information in A Computer
A Is The Most Basic Unit of Information in A Computer
1
Digital Representations
Binary Representation
• Only two states (0 and 1)
• The binary system is also called the base-2
system MSB LSB
2
Digital Representations
Binary Representation
MSB
Nibble
3
Digital Representations
Decimal to binary
Example : Converting 0.8125 to binary
...
• You are finished when the product is zero,
or until you have reached the desired
number of binary places.
• Our result, reading from top to bottom is:
0.812510 = 0.11012
• This method also works with any base.
Just use the target radix as the multiplier.
Note : It is difficult to read long strings of
binary numbers-- and even a modestly-
sized decimal number becomes a very
long binary number.(hence Hex)
4
Digital Representations
5
Digital Representations
6
Digital Representations
1101000101 = (345)16
7
Digital Representations
Example for n = 4.47
8
Digital Representations
9
Digital Representations
10
Digital Representations
Fixed Precision
• Beware of overflow problems!
• Microprocessors limit numbers to a fixed number of bits:
255 = 11111111 = FF
+ 1 = 00000001 = 01
-------------------
256 00000000 = 00
F + 1 = 0, carry
F + 1 (carry) + 0 = 0, carry
Carry out of MSB falls off the end because there is no place to put it!
12
Digital Representations
Signed numbers
• Signed numbers, require an arithmetic sign. The
most significant bit of a binary number is used to
represent the sign bit. If the sign bit is equal to
zero, the signed binary number is positive;
otherwise, it is negative.
• The remaining bits represent the actual number.
There are three ways to represent negative
numbers.
1. Sign-Magnitude Representation
2. One's-Complement Representation
3. Two’s complement.
13
Digital Representations
Signed Magnitude Representation
In an 8-bit word, signed magnitude representation
places the absolute value of the number in the 7
bits to the right of the sign bit
14
Digital Representations
• Example:
• Using signed magnitude
binary arithmetic, find the
sum of 75 and 46.
• First, convert 75 and 46 to
binary, andinarrange
For example, asmagnitude,
8-bit signed a sum,
Positive
but 3 is:
separate 00000011
the (positive) sign
Negative 3 is: 10000011
bits from the magnitude bits.
15
Digital Representations
• Example:
• Using signed magnitude binary
arithmetic, find the sum of 107
and 46.
• We see that the carry from the
seventh bit overflows and is
For example, giving
discarded, in 8-bit signed
us themagnitude,
Positive 3 is: 00000011
erroneous
Negative 3 is:result: 107 + 46 = 25.
10000011
16
Digital Representations
17
Digital Representations
18
Digital Representations
19
Digital Representations
20
Digital Representations
• With two’s complement arithmetic, all we do is add
our two binary numbers. Just discard any carries
emitting from the high order bit.
21
Digital Representations
Signed Integers
• Does arithmetic still work?
Example: What is the sum of (-128)10 + (127)10 in binary representation?
(Verify by converting the result to decimal representation.)
22
Digital Representations
23
Digital Representations
24
Digital Representations
• Example:
• Using two’s complement binary
arithmetic, find the sum of 107
and 46.
• We see that the nonzero carry from
the seventh bit overflows into the
sign bit, giving us the erroneous
result: 107 + 46 = -103.
25
Digital Representations
26
Digital Representations
27
Digital Representations
Floating-Point Representation
• The signed magnitude, 1’s complement, and
2’s complement representations as such are
not useful in scientific or business applications
that deal with real number values over a wide
range.
• Floating-point representation solves this
problem.
28
Digital Representations
29
Digital Representations
30
Digital Representations
31
Digital Representations
32
Digital Representations
33
Digital Representations
• Example:
• Express 3210 in the simplified 14-bit floating-point
model.
• We know that 32 is 25. So in (binary) scientific notation 32
= 1.0 x 25 = 0.1 x 26.
• Using this information, we put 110 (= 610) in the exponent
field and 1 in the significand as shown.
34
Digital Representations
• The illustrations shown
at the right are all
equivalent
representations for 32
using our simplified
model.
• Not only do these
synonymous
representations waste
space, but they can also
cause confusion.
35
Digital Representations
36
Digital Representations
37
Digital Representations
38
Digital Representations
• Example:
• Express 3210 in the revised 14-bit floating-point model.
• We know that 32 = 1.0 x 25 = 0.1 x 26.
• To use our excess 16 biased exponent, we add 16 to 6,
giving 2210 (=101102).
• Graphically:
39
Digital Representations
• Example:
• Express 0.062510 in the revised 14-bit floating-point
model.
• We know that 0.0625 is 2-4. So in (binary) scientific
notation 0.0625 = 1.0 x 2-4 = 0.1 x 2 -3.
• To use our excess 16 biased exponent, we add 16 to -3,
giving 1310 (=011012).
40
Digital Representations
• Example:
• Express -26.62510 in the revised 14-bit floating-point
model.
• We find 26.62510 = 11010.1012. Normalizing, we have:
26.62510 = 0.11010101 x 2 5.
• To use our excess 16 biased exponent, we add 16 to 5,
giving 2110 (=101012). We also need a 1 in the sign bit.
41
Digital Representations
42
Digital Representations
43
Digital Representations
44
Digital Representations
• Example:
• Find the sum of 1210 and 1.2510 using the 14-bit floating-
point model.
• We find 1210 = 0.1100 x 2 4. And 1.2510 = 0.101 x 2 1 =
0.000101 x 2 4.
45
Digital Representations
• Floating-point multiplication is also carried out in a
manner akin to how we perform multiplication using
pencil and paper.
• We multiply the two operands and add their
exponents.
• If the exponent requires adjustment, we do so at the
end of the calculation.
46
Digital Representations
• Example:
• Find the product of 1210 and 1.2510 using the 14-bit
floating-point model.
• We find 1210 = 0.1100 x 2 4. And 1.2510 = 0.101 x 2 1.
47
Digital Representations
• No matter how many bits we use in a floating-point
representation, our model must be finite.
• The real number system is, of course, infinite, so our
models can give nothing more than an approximation
of a real value.
• At some point, every model breaks down, introducing
errors into our calculations.
• By using a greater number of bits in our model, we
can reduce these errors, but we can never totally
eliminate them.
48