标签:技术分享 pen view 程序 button span 整数 reverse code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String[] two = {
"0", "1", "2", "3",
"4", "5", "6", "7",
"8", "9", "A", "B",
"C", "D", "E", "F",
};
Scanner cin = new Scanner(System.in);
long a = cin.nextLong();
StringBuilder toTwo = new StringBuilder();
if(a == 0) {
System.out.println("0");
return ;
}
while(a != 0) {
toTwo.append(a % 2 + "");
a = a / 2;
}
int len = toTwo.length();
// String toTwo2 = toTwo.toString();
if(len % 4 == 1) {
toTwo.append("000");
}
else if(len % 4 == 2) {
toTwo.append("00");
}
else if(len % 4 == 3) {
toTwo.append("0");
}
len = toTwo.length();
StringBuilder ans = new StringBuilder();
for(int i = 0; i < len - 3; i += 4) {
int t = (toTwo.charAt(i) - ‘0‘) * 1 + (toTwo.charAt(i+1) - ‘0‘) * 2 +
(toTwo.charAt(i+2) - ‘0‘) * 4 + (toTwo.charAt(i+3) - ‘0‘) * 8;
ans.append(two[t]);
}
System.out.println(ans.reverse());
}
}
标签:技术分享 pen view 程序 button span 整数 reverse code
原文地址:https://www.cnblogs.com/zhumengdexiaobai/p/10347317.html