المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Convert Hexadecimal into Binary and Long in java - source code



A7med Baraka
03-25-2009, 06:40 PM
Convert Hexadecimal into Binary and Long in java - source code




import java.io.*;
import java.lang.*;
/**
*
* @author A7med Baraka
* www.barakasoft.com
*/
public class HexadecimalToBinaryAndLong{
public static void main(String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the hexa value!");
String hex = bf.readLine();
int i = Integer.parseInt(hex);
String by = Integer.toBinaryString(i);
System.out.println("This is Binary: " + by);
long num = Long.parseLong(hex,16);
System.out.println("This is long:=" + num);
}
}

A7med Baraka
03-25-2009, 06:47 PM
Convert Hexadecimal into Binary and Long in java - source code

Another Source Code working well and handled some cases





import java.io.*;
/**
*
* @author A7med Baraka
* www.barakasoft.com
*/
public class HexToByteConverter{

public static void main(String[] args) throws IOException{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while (!(line = br.readLine()).equals("")){
for (int i = 0,j = line.length(); i < j; i++){

System.out.print(Integer.toBinaryString(Character.digit(line.charAt(i),16))+" ");
}
System.out.println();
}
}
}