言语,翟鸿燊点亮心灯,蜗居无删减版
public static void main(string[] args) { system.out.println(tobin(6)); system.out.println(tohex(0)); system.out.println(tooct(8)); } public static string tobin(int num){ return trans(num,1,1); } public static string tohex(int num){ return trans(num,15,4); } public static string tooct(int num){ return trans(num,7,3); } public static string trans(int num, int base, int offset){ if (num ==0) return "0"; char[] chs = {'0','1','2','3','4','5','6','7','8','9','a','b','c','b','e','f'}; char[] arr = new char[32]; int pos=arr.length; while (num!=0){ int temp = num & base; arr[--pos]=chs[temp]; num = num >>> offset; } stringbuffer stringbuffer = new stringbuffer(); for (int i = pos; i < arr.length; i++) { stringbuffer.append(arr[i]); } return stringbuffer.tostring(); }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论