gpt4 book ai didi

javascript - 如何将二进制字符串转换为十进制?

转载 作者:IT老高 更新时间:2023-10-28 21:50:21 24 4
gpt4 key购买 nike

我想将二进制字符串转换为数字例如

var binary = "1101000" // code for 104
var digit = binary.toString(10); // Convert String or Digit (But it does not work !)
console.log(digit);

这怎么可能?谢谢

最佳答案

parseInt函数将字符串转换为数字,它需要第二个参数指定字符串表示的基数:

var digit = parseInt(binary, 2);

See it in action

关于javascript - 如何将二进制字符串转换为十进制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10258828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com