how to convert binary string to decimal?

后端 未结 9 2231
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 04:41

I want to convert binary string in to digit E.g

var binary = \"1101000\" // code for 104
var digit = binary.toString(10); // Convert String or Digit (But it          


        
9条回答
  •  一向
    一向 (楼主)
    2020-11-28 05:06

    The parseInt function converts strings to numbers, and it takes a second argument specifying the base in which the string representation is:

    var digit = parseInt(binary, 2);
    

    See it in action.

提交回复
热议问题