Sunday, 3 November 2019

How to convert binary fraction to decimal

Javascript has the function parseInt() which can help convert integer in a binary form into its decimal equivalent:

parseInt("101", 2) // 5

However, I need to convert binary fraction to its decimal equivalent, like:

0.101 = 0.625

I can write my own function that would calculate the result like the following:

1 * Math.pow(2, -1) + 0*Math.pow(2, -2) + 1*Math.pow(2, -3) // 0.625

But I'm wondering whether there is anything standard already.



from How to convert binary fraction to decimal

No comments:

Post a Comment