如题:
public class Test { public static void main(String[] args) { String s = "01800B0200F40C07181870300300000020C000C303030C0C0C303030C0C0E30303EFFFFDFFFFF0C0C0C303030C0C0C303030C0C0C300030000030"; //String s = "00C0100301E00C7E3FFFC0C0C00303002C0C00B03006FFFFF80300000C0380307C7FFF83FF800C0C00303003C0C00F03002FFFFF80300000C000030000"; String bin = hexToBin(s); int step = 22; //for (int i = 0; i < bin.length(); i+=step) { // System.out.println(bin.substring(i, i+step>bin.length()?bin.length():i+step)); //} for (int i = 0; i < 22; i++) { int j = i; while(j < bin.length() ){ System.out.print(bin.charAt(j>bin.length()-1?bin.length()-1:j)); j += step; } System.out.println(); } } public static String hexToBin(String hex){ String bin = ""; String binFragment = ""; int iHex; hex = hex.trim(); hex = hex.replaceFirst("0x",""); for(int i = 0; i < hex.length(); i++){ iHex = Integer.parseInt(""+hex.charAt(i),16); binFragment = Integer.toBinaryString(iHex); while(binFragment.length() < 4){ binFragment = "0" + binFragment; } binFragment = binFragment.replaceAll("0", " "); bin += binFragment; //System.out.print(binFragment); //int j = 7; //if (i % j == j-1) { // System.out.println(); //} } return bin; } }
标签:bin,Java,String,点阵图,int,hex,length,binFragment,按键精灵 From: https://www.cnblogs.com/marshwinter/p/16918107.html