any idea how do i flush off the leading 0s from my results? I want to start with 1.
import java.util.Scanner; public class Hex2Bin { public static void main(String[] args) { String hexStr; int hexStrLen; String[] binStrs = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"}; Scanner in = new Scanner(System.in); System.out.print("Enter a Hexadecimal string: "); hexStr = in.next(); hexStrLen = hexStr.length(); System.out.print("The binary equivalent is: "); for (int pos = 0; pos <hexStrLen; ++pos){ char hexChar = hexStr.charAt(pos); if (hexChar >= '0' && hexChar <='9') { System.out.print(binStrs[hexChar-'0']); }else if (hexChar >= 'a' && hexChar <='f'){ System.out.print(binStrs[hexChar-'a'+10]); }else if (hexChar >= 'A' && hexChar <= 'F'){ System.out.print(binStrs[hexChar-'A'+10]); }else{ System.out.println("error: invalid hexadecimal number"); return; } } } }