如何将二进制表示中的字节转换为java中的int
发布时间:2020-12-15 05:02:59 所属栏目:Java 来源:网络整理
导读:我有一个带字节值的String [] String[] s = {"110","101","100","11","10","1","0"}; 循环使用s,我想从中获取int值. 我目前正在使用它 Byte b = new Byte(s[0]); // s[0] = 110int result = b.intValue(); // b.intValue() is returning 110 instead of 6 从
我有一个带字节值的String []
String[] s = {"110","101","100","11","10","1","0"}; 循环使用s,我想从中获取int值. 我目前正在使用它 Byte b = new Byte(s[0]); // s[0] = 110 int result = b.intValue(); // b.intValue() is returning 110 instead of 6 从那以后,我试图得到结果,{6,5,4,3,2,1} 我不知道从哪里开始.我能做什么? 多谢你们.问题回答了. 解决方法
您可以使用重载的
Integer.parseInt(String s,int radix) 方法进行此类转换.这样你就可以跳过Byte b = new Byte(s [0]);一段代码.
int result = Integer.parseInt(s[0],2); // radix 2 for binary (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |