如何打印二进制和16进制

myhotsun 2004-04-08 03:21:51
假如有一个Byte类型的数据,如何以二进制和16进制形式把他打印出来啊!
...全文
1270 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ngqzmjmj 2004-04-08
  • 打赏
  • 举报
回复
to : bigcrazy(大疯狂) ( )
byte转换 int 从小到大的转换 好象没什么问题吧
ngqzmjmj 2004-04-08
  • 打赏
  • 举报
回复
byte b= 9;
System.out.println(Integer.toBinaryString(b));//2
System.out.println(Integer.toHexString(b));//16
bigcrazy 2004-04-08
  • 打赏
  • 举报
回复
Integer有个方法:static String toBinaryString(int i)
Creates a string representation of the integer argument as an unsigned integer in base 2.
以及:static String toHexString(int i)
Creates a string representation of the integer argument as an unsigned integer in base 16.

BYTE转成INT的时候要注意一点负数的问题。

62,623

社区成员

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

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