eXtreme Development

Java - convert hexa to binary

import java.util.Scanner;

public class JavaHexToBin  
{  
public static void main(String[]args)  
{  
 String[]hex={"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};  
 String[]binary={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};  
 Scanner s=new Scanner(System.in);  
 System.out.print("Put hex value : ");  
 String userInput=s.next();  
 String result="";  
 for(int i=0;i<userInput.length();i++)  
 {  
  char temp=userInput.charAt(i);  
  String temp2=+temp+;  
  for(int j=0;j<hex.length;j++)  
  {  
   if(temp2.equalsIgnoreCase(hex[j]))  
   {  
    result=result+binary[j];  
   }  
  }  
 }  
 System.out.println("IT'S BINARY IS : "+result);  
}  
}  


SourceForge BootStrap