How do I convert a very long binary number to decimal?

前端 未结 3 1510
走了就别回头了
走了就别回头了 2020-12-06 18:50

I have a binary number represented as 11.1111111 (the . being analogous to a decimal point). There are 2 bits before the point, and 1024 bits after the point. It was an exer

3条回答
  •  無奈伤痛
    2020-12-06 19:16

    You can use System.Numerics BigInteger. It can hold massive numbers. https://msdn.microsoft.com/en-us/library/system.numerics.biginteger%28v=vs.110%29.aspx

    EDIT: I thought the binary after the decimal was to be counted as usual. Thus the last bit would be 2^1 where 1 would increase all the way to the dot. This renders a number looking something like 1.2*10^308. Which would then truncate to 2.12......

    But it is actually the first bit after the dot being counted as 2^-1 and -1 being decreased to 2^-1024. Thus rendering a 0.x number which cannot be represented by a BigInteger.

提交回复
热议问题