如何将二进制字符串值转换为十进制 [英] How to convert binary string value to decimal

查看:319
本文介绍了如何将二进制字符串值转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何转换二进制字符串,例如

How to convert a binary String such as

String c = "110010"; // as binary

到Java中的十进制值? (示例中的预期结果是50)

to the value in decimal in Java? (expected result in the example is 50)

推荐答案

使用 Integer.parseInt (参见 javadoc ),使用基数2将 String 转换为 int

Use Integer.parseInt (see javadoc), that converts your String to int using base two:

int decimalValue = Integer.parseInt(c, 2);

这篇关于如何将二进制字符串值转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆