`
davepkxxx
  • 浏览: 40401 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

面试时候遇到的一道十进制转十六进制笔试题,顺便记录下来

阅读更多
public class util {

	public static String decimalToHex(int decimal) {
		String hex = "";

		for (; decimal > 0; decimal /= 16) {
			int remainder = decimal % 16;
			
			if (remainder > 10) {
				hex = (char) ('A' + remainder - 10) + hex;
			} else {
				hex = remainder + hex;
			}
		}

		return hex;
	}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics