Reputation: 21
I would like to write a program that converts a floating point binary number into decimal. I know how to convert a normal binary number into decimal but I would like to convert a floating point binary into decimal with a mantissa of 10 and a exponent of 6.
At the same time I would like to use input to gain the binary value e.g.
System.out.println("Enter a binary number");
Then use a scanner to gain input. Is this possible?
Upvotes: 2
Views: 948
Reputation: 37645
Given a String
like "101011.1011"
, one approach is:
String.split
.BigInteger
constructor BigInteger(String s, int radix)
with radix == 2
to get the two BigInteger
s representing 1010111011
and 10000
.BigDecimal
constructor taking BigInteger
to convert to BigDecimal
.I don't know if there's a simpler way.
Upvotes: 2