How to convert binary fraction to decimal

前端 未结 6 1165
北荒
北荒 2020-12-10 10:52

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

parseInt(\"101\", 2) // 5
         


        
6条回答
  •  时光取名叫无心
    2020-12-10 11:23

    My logic behind is parseInt(res[0] + res[1], base) / Math.pow(base, res[1].length);

    Ex : var fValue = '-1100.0011'; var result= parseInt('-11000011', base) / Math.pow(base, '0011'.length);

提交回复
热议问题