首页  

c语言整数进制     所属分类 c 浏览量 742
int i = 10;
// 10 12 a 
printf("%d %o %x \n",i,i,i);
i = 21;
printf("%d %o %x \n",i,i,i);
i = -21;
-21 37777777753 ffffffeb 
printf("%d %o %x \n",i,i,i);
// 数字零开头 八进制
i = 012;
printf("%d %o %x \n",i,i,i);
i = 00012;
printf("%d\n",i);
	
i = 12;
printf("%d\n",i);

// 数字零x  六十进制
i = 0x12;
printf("%d\n",i); 
	



输出 10 12 a 21 25 15 -21 37777777753 ffffffeb 10 12 a 10 12 18
radix 基数 public class IntTest { public static void main(String[] args) throws Exception { int value = 21; String str = Integer.toString(value, 2); System.out.println(str); System.out.println(Integer.parseInt(str, 2)); toString(21); toString(-21); } private static void toString(int value) { StringBuilder sb = new StringBuilder(); sb.append(value).append(" "); sb.append(Integer.toString(value, 2)).append(" "); sb.append(Integer.toString(value, 8)).append(" "); sb.append(Integer.toString(value, 16)).append(" "); sb.append(Integer.toBinaryString(value)).append(" "); sb.append(Integer.toOctalString(value)).append(" "); sb.append(Integer.toHexString(value)).append(" "); System.out.println(sb.toString()); } } 输出 10101 21 21 10101 25 15 10101 25 15 -21 -10101 -25 -15 11111111111111111111111111101011 37777777753 ffffffeb

上一篇     下一篇
lua for 循环

Lua 语法 总结

全球ETF行业发展2020年度报告

C语言猜数字

java 猜数字

go猜数字游戏