package StackTest;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import static tools.LogUtils.log;
public class toHex {
public static void main(String[] args) {
String hex = toHex(12500);
log.info(hex);
if (hex.equalsIgnoreCase("30D4")) {
System.out.println("测试通过");
} else {
System.out.println("测试失败");
}
static String toHex(int n) {
Deque<String> q=new LinkedList<>();
String str="";
int mod;
do {
mod=n%16;
n=n/16;
q.push(Integer.toHexString(mod).toUpperCase());
} while (n!=0);
str += q.pop();
} while (q.size()>=1);
return str;
Sign in to make a reply
净净一隅
package StackTest;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import static tools.LogUtils.log;
public class toHex {
public static void main(String[] args) {
String hex = toHex(12500);
log.info(hex);
if (hex.equalsIgnoreCase("30D4")) {
System.out.println("测试通过");
} else {
System.out.println("测试失败");
}
}
static String toHex(int n) {
Deque<String> q=new LinkedList<>();
String str="";
int mod;
do {
mod=n%16;
n=n/16;
q.push(Integer.toHexString(mod).toUpperCase());
} while (n!=0);
do {
str += q.pop();
} while (q.size()>=1);
return str;
}
}