public static void main(String[] args ){ int i = 8; String s2 = Integer.toString(i,2); System.out.println(\"2进制为:\"+s2); // -- 1000 int sum = 0; for (int j = 0; j < s2.length(); j++) { int x = Integer.parseInt(String.valueOf(s2.charAt(j))); sum += x * Math.pow(2,(s2.length()-j-1)); } System.out.println(\"10进制为:\"+sum); }
来源:https://www.cnblogs.com/c2g5201314/p/15962841.html
本站部分图文来源于网络,如有侵权请联系删除。