10-》2
private void pBinInt(String s, int i) {
System.out.println(
s + ", int: " + i + ", binary: ");
System.out.print(" ");
for(int j = 31; j >=0; j--) //代码A
{
if(((1 << j) & i) != 0)
System.out.print("1");
else
System.out.print("0"); //代码B
System.out.println("1<<j="+(1 << j));
}
System.out.println();
}
private void pBinInt(String s, int i) {
System.out.println(
s + ", int: " + i + ", binary: ");
System.out.print(" ");
for(int j = 31; j >=0; j--) //代码A
{
if(((1 << j) & i) != 0)
System.out.print("1");
else
System.out.print("0"); //代码B
System.out.println("1<<j="+(1 << j));
}
System.out.println();
}
解决方案 »
- iterator迭代器问题
- 如何获取远程主机显示器
- 我使用Layout(null)布局时,JButton按钮出发一次就布局一次【附有源代码】
- 通过jdbc连接SQLServer2000报错
- 請問Table從數據庫當中獲取資料出來之後,如何能點選某一列讓該列的資訊傳回到表頭顯示?
- 如何用JMF实现语音聊天,分儿有的事
- 哪未前辈可以推荐2本除学JAVA的教材,本人计算机系
- 请问那位有jbuild7企业版的注册码,给我发一份ok?
- @@@@@@@@@@motorola正在举办388java程序设计大赛,大家做得如何了??
- 怎样制作java的声音格式.AU文件啊?用什么工具?
- 关于父类跟子类之间的转换问题,能人请进...
- 几个小问题(100)分
String s1 = Integer.toBinaryString(i);
String s2 = Integer.toHexString(i);
String s3 = Integer.toOctalString(i);
byte b = Byte.parseByte("1011", 2); // 二进位的 1011 , 在十进位中则是 11
short sh = Short.parseShort("ff", 16); // 十六进位的 ff , 在十进位中为 255 // valueOf() 方法可以处理任意的基底(base)
int i = Integer.valueOf("egg", 17).intValue(); // 以 17 为基底 // decode() 方法可以处理八进位、十进位或十六进位
// 要看该字串前面的数字为何
short sh = Short.decode("0377").byteValue(); // 以 0 开头表示是八进位
int i = Integer.decode("0xff").shortValue(); // 以 0x 开头表示是十六进位
long l = Long.decode("255").intValue(); // 其他的数字则表示是十进位 // 能将数字转换为字串的 Integer 类别
String decimal = Integer.toString(42);
String binary = Integer.toBinaryString(42);
String octal = Integer.toOctalString(42);
String hex = Integer.toHexString(42);
String base36 = Integer.toString(42, 36);