0x12345怎样格式化输出为00012345?

iwillalwaysloveyou 2007-03-21 05:22:44
如题,谢谢了
...全文
394 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
inthistime 2007-03-23
  • 打赏
  • 举报
回复
java也还是一条语句,只是你要求转化成8位罢了。

java的一些优势C/C++也是做不到的,不是吗?
iwillalwaysloveyou 2007-03-22
  • 打赏
  • 举报
回复
up
iwillalwaysloveyou 2007-03-22
  • 打赏
  • 举报
回复
哪位知道请赐教,谢谢!
iwillalwaysloveyou 2007-03-22
  • 打赏
  • 举报
回复
java真他奶奶的麻烦,C/C++一条语句搞定的事儿
inthistime 2007-03-22
  • 打赏
  • 举报
回复
这个更简捷一点!

public class longToString
{
public static void main(String[] args)
{
long longTest=0x012345;
String stringTest=Long.toHexString(longTest);
for(int j=1;j<=8-stringTest.length();j++)
stringTest="0"+stringTest;
System.out.println(stringTest);
}
}
inthistime 2007-03-22
  • 打赏
  • 举报
回复
全部源码如下:

public class longToString
{
public static void main(String[] args)
{
long longTest=0x012345;
String stringTest=Long.toHexString(longTest);
String temp;
int i=8-stringTest.length();
for(int j=1;j<=i;j++)
stringTest="0"+stringTest;
System.out.println(stringTest);
}
}

OK,真应该给分了!
inthistime 2007-03-22
  • 打赏
  • 举报
回复
long longTest=0x01234;
String stringTest=Long.toHexString(longTest);
System.out.println(stringTest);

你再在前面按长度加"0"就可以了!

OK,给分吧!
zhuokai 2007-03-22
  • 打赏
  • 举报
回复
private String convertHexToStr(int a)
{
String test = Integer.toHexString(a);
if(test.length() < 8)
{
StringBuffer sb = new StringBuffer();
for(int i=0;i<8-test.length();i++)
sb.append('0');
sb.append(test);
return sb.toString()
}
else
return test;
}

//test
//int a = 0x12345;
//String test = convertHexToStr(a);
KevinXie 2007-03-22
  • 打赏
  • 举报
回复
0x12345怎样格式化输出为00012345?
不太明白楼主要表达的意思.

假如是进制的转换,Ox12345对应的十进制是74565,如果只是将16进制输出为10进制,那直接输出变量就可以了,默认数值型输出是10进制的.

假如这是字符串,那也简单,按你的要求,也就是将Ox替换成000,剩下的数原样输出

===============
说实话,楼主你的问题描述太难理解了,希望你把你的问题描述清楚,或者把你的代码帖出来,再吧你的要求一说,大家一看就明白了.现在这样子,都不知道你那些是数字还是字符,还是什么别的东西?
qfs_v 2007-03-21
  • 打赏
  • 举报
回复
进制问题!
iwillalwaysloveyou 2007-03-21
  • 打赏
  • 举报
回复
up
iwillalwaysloveyou 2007-03-21
  • 打赏
  • 举报
回复
晕倒,0x12345指16进制的12345
www203 2007-03-21
  • 打赏
  • 举报
回复
无论如何
帮定
楼主是要把一个X换成2个0吗?

62,636

社区成员

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

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