Convert Hexadecimal into Binary and Long in java - source code
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);
}
}
رد: Convert Hexadecimal into Binary and Long in java - source code
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();
}
}
}