懒人不愿做题,所有的东西都用程序跑出来是最好的,下面做一个十进制、八进制、十六进制数互相转换的小程序
public class JZTurn {
public static void main(String[] args) {
int num2 = 1314521;
System.out.println("十进制数:"+num2);
System.out.println("十进制转换二进制:"+turn2(num2));
System.out.println("十进制转换八进制:"+turn8(num2));
System.out.println("十进制转换十六进制:"+turn16(num2));
//2-> 8
System.out.println("二进制转换八进制:"+twoTurnEight(turn2(num2)));
System.out.println("八进制转换二进制:"+eightTurnTwo(turn8(num2)));
System.out.println("八进制转换十六进制:"+eightTurnSixteen(turn8(num2)));
//2->16
System.out.println("二进制转换十六进制:"+twoTurnSixteen(turn2(num2)));
}
/**
* 10进制转二进制
* @param num
* @return
*/
public static String turn2(int num){
String shortTimeNum = "";
int remainder = 0;
/**
* 模拟短除法
*/
while(num >= 1){
remainder = num % 2;
num = num / 2;
s