笔试题:将输入的数字转为成四进制表示。
package com.spring.demo.controller; /** * @author wxe * @since 1.0.0 */ public class FourTest { public static void main(String[] args) { System.out.println(getFourHex(520)); } final static char[] digits = { '0', '1', '2', '3' };// 四进制表示数0,1,2,3 public static String getFourHex(int origin) { char[] result = new char[32]; int charPostion = 32; while ((origin / 4) > 0) { result[--charPostion] = digits[origin % 4]; origin = origin / 4; } result[--charPostion] = digits[origin % 4]; return new String(result,charPostion,32-charPostion); } }
测试:520 对应的四进制为:20020
posted on
浙公网安备 33010602011771号