Java 的数据转换二进制,十六进制,八进制 怎么转换

liusen 2006-05-07 05:21:00
在Java的基本数据 怎么转换为二进制,十六进制,八进制哦?
...全文
893 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxg12345 2007-03-18
  • 打赏
  • 举报
回复
没错了,
Integer.toHexString(int i);
Integer.toOctalString(int i);
Intege.toBinaryString(int i);
liusen 2007-03-18
  • 打赏
  • 举报
回复
dd
dandan_liag 2006-05-09
  • 打赏
  • 举报
回复
楼上的说的转换后的结构都是String了,其实在java中是没有二进制数的。
f_acme 2006-05-08
  • 打赏
  • 举报
回复
在5.0还有一种像c语言的写法:
public class Test
{
public static void main(String args[])
{
int factor = 10;
System.out.printf("%d\n", factor);
System.out.printf("%x\n", factor);
System.out.printf("%o\n", factor);
}
}
sheep219 2006-05-08
  • 打赏
  • 举报
回复
16进制 Integer.toHexString(int i)
8进制 Integer.toOctalString(int i)
2进制 Integer.toBinaryString(int i)
比较常用

s = String.format("%d", factor);
System.out.println(s);
s = String.format("%x", factor);
System.out.println(s);
s = String.format("%o", factor);
System.out.println(s);

应该是5.0以后才有的
UnAgain 2006-05-08
  • 打赏
  • 举报
回复
mark
zuguanqun 2006-05-08
  • 打赏
  • 举报
回复
String bin=Integer.toBinaryString(内容); 2
String otc=Integer.toOctalString(内容); 8
String hex=Integer.toHexString(内容); 16
wjs2338 2006-05-08
  • 打赏
  • 举报
回复
看看API,在Integer类里面有转成 16进制,8进制和2进制的函数
16进制 Integer.toHexString(int i)
8进制 Integer.toOctalString(int i)
2进制 Integer.toBinaryString(int i)
Camelh 2006-05-08
  • 打赏
  • 举报
回复
int i=100;
String binStr=Integer.toBinaryString(i);
String otcStr=Integer.toOctalString(i);
String hexStr=Integer.toHexString(i);
System.out.println(binStr);
System.out.println(otcStr);
System.out.println(hexStr);
treeroot 2006-05-08
  • 打赏
  • 举报
回复
toHexString
toBinaryString
做鸡真好吃 2006-05-08
  • 打赏
  • 举报
回复
up~
UnAgain 2006-05-07
  • 打赏
  • 举报
回复
public class TestStringFormat {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("usage: java TestStringFormat <a number>");
System.exit(0);
}

Integer factor = Integer.valueOf(args[0]);

String s;

s = String.format("%d", factor);
System.out.println(s);
s = String.format("%x", factor);
System.out.println(s);
s = String.format("%o", factor);
System.out.println(s);
}
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧