Java Reference
In-Depth Information
The ciphers representing the number can be found iteratively using the
following equations:
value
i
B
i
B
i
+
1
value
n
=
number
;
c
i
=
;
value
i
=
value
i
+
1
−
c
i
+
1
·
Equation 6.4
Ciphers for representation in base B
Representation format
The most used format is the fixed point format: it is the basic positional
format described above. The other two formats are based on the fixed point
format. According to the floating point format a number is represented as:
B
exponent
number
=
mantissa
·
Equation 6.5
Floating point format
Here
mantissa
is a fixed point number that has a single cipher before the
decimal point,
B
is the base, and
exponent
is an integer number (i.e. a fixed
point with no cipher after the decimal point). The conversion between a
fixed point and a floating point format can be performed using the following
formula, where
c
i
is a cipher of the fixed point format while
f
i
is a cipher of
the mantissa of the floating point number.
B
n
−
1
c
n
...
c
2
c
1
c
0
.
c
−
1
c
−
2
...
c
−
m
=
f
0
.
f
−
1
f
−
2
...
f
−
(
n
+
m
−
1)
+
Equation 6.6
Equivalence between fixed point and floating point
The fractional format is the most common way of representing rational
numbers. A number is represented as the division of numerator and denom-
inator:
numerator
denominator
number
=
Equation 6.7
Fractional format
6.2.2
Main features
We are now able to summarize all the main features emerging from the
problem analysis.
Arithmetic operations
. The calculator should be able to perform binary
arithmetic operations.
■
Multi-format representation
. The calculator should allow the user to
insert operands in different number formats, to switch between formats,
and to convert results from one format to another.
■
Multi-base representation
. Similarly, the calculator should allow the user
to insert operands in different number bases, to switch between bases,
and to convert results from one base to another.
■