如何将二进制字符串转换为十进制? [英] how to convert binary string to decimal?
本文介绍了如何将二进制字符串转换为十进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将二进制字符串转换为数字
例如
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 does not work !)
console.log(digit);
怎么可能?
谢谢
How is it possible? Thanks
推荐答案
parseInt
函数将字符串转换为数字,它采用第二个参数指定字符串表示的基数是:
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.
这篇关于如何将二进制字符串转换为十进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文