进制转换代码java 进制转换代码c语言( 二 )


String bin = Integer.valueOf("0101",2).toString();
System.out.println(bin);
}catch (Exception e){
e.printStackTrace();
}
java 中十进制与四进制互转代码【高分】试试下面进制转换代码java的代码进制转换代码java,可以把10进制转换为2~36之间的任意进制进制转换代码java , 也可以把2~36之间的任意进制数转成10进制 。
百度勿吞进制转换代码java!进制转换代码java?。?
public class NumberToNumber {
public static String[] arr = {"0","1","2","3","4","5","6","7","8",
"9","A","B","C","D","E","F","G","H",
"I","J","K","L","M","N","O","P","Q",
"R","S","T","U","V","W","X","Y","Z"};
public static String numbers = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public String tenToAll(int num,int base){
if(base2 || basearr.length){
return String.valueOf(num);
}
String result = "";
do{
result = arr[num%base] + result;
num = (num - num%base)/base;
}while(num/base != 0);
result = num==0?result:arr[num] + result;
return result;
}
public int allToTen(String num,int base) throws Exception{
num = num.toUpperCase();
int d = 0;
int len = num.length();
for(int i=0;ilen;i++){
char sub = num.charAt(i);
【进制转换代码java 进制转换代码c语言】int val = numbers.indexOf(sub);
if(val == -1 || valbase){
throw new Exception();
}
d+= val * Math.pow(base, len - i - 1);
}
return d;
}
public static void main(String[] args) {
NumberToNumber n = new NumberToNumber();
try {
String num = "123322";
int result = n.allToTen(num, 4);
System.out.println(result);
System.out.println(n.tenToAll(result, 4));
} catch (Exception e) {
System.err.println("非法数字!");
}
}
}
java十进制转换String代码?十进制转String, 和String转十进制的参考方法如下:
public class Test {
public static void main(String[] args) {
int a = 123;
//十进制转字符串
String s1 = a + "";//方法1:字符串拼接得到字符串
String s2 = String.valueOf(a);//方法2:使用String.valueOf方法转换得到字符串
//字符串转十进制
int x = Integer.valueOf(s1);//方法1
int y = Integer.parseInt(s2);//方法2
int z = new Integer(s1);//方法3
}
}
跪求“java中二进制怎么表示”java中二进制的表示进制转换代码java:
1、Java中定义两个数进制转换代码java,然后分别打印出它们的二进制表示(例如7和-7):
System.out.println("Java二进制7: "+Integer.toBinaryString(7));
System.out.println("Java二进制-7: "+Integer.toBinaryString(-7));
输出:
Java二进制7: 111
Java二进制-7: 11111111111111111111111111111001
7的二进制就是111
-7转化二进制的过程:
(1)把-7转化成7进制转换代码java , 二进制是 111
(2)Java中对于不满32位的int二进制自动补齐,所以变成了 (29个0)111
(3)然后取反(29个1)000
(4)然后加1 (29个1)001
扩展资料:
c语言中二进制的转换:
用函数转换itoa(值,数组名,进制)
#includestdio.h
#includestdlib.h
void main()
{
char str[8];
int i=8;
itoa(i,str,2);
printf("%s",str);
}
参考资料:
java二进制——百度百科
关于进制转换代码java和进制转换代码c语言的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读