Home Java Java-conversion Convert Hexadecimal into Binary and Long



Convert Hexadecimal into Binary and Long
Posted on: June 15, 2007 at 12:00 AM
In this section, you will learn to convert the hexadecimal data into the binary and long format.

Convert Hexadecimal into Binary and Long

     

In this section, you will learn to convert the hexadecimal data into the binary and long format. The java.lang package provides the functionality to convert a hexadecimal to binary and long type data. 

Code Description:

This program helps you in converting the hexadecimal data into the binary and long. At run time this program asks for a  a hexadecimal data and it then converts it into an integer type data. The toBinaryString() method converts an integer data into binary data. And the parseLong() method converts the hexadecimal data into a long type data.

Here is the code of this program:

import java.io.*;
import java.lang.*;

public class HexadecimalToBinaryAndLong{
  public static void main(String[] argsthrows 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);
  }

Download this program:

Output of this program.

C:\vinod\convert>javac HexadecimalToBinaryAndLong.java

C:\vinod\convert>java HexadecimalToBinaryAndLong
Enter the hexa value!
14
This is Binary: 1110
This is long:=20

Related Tags for Convert Hexadecimal into Binary and Long:
javacidedatatimefunctionbinaryconvertfuniohelpintegertypehexvidecimalintthisidpackagefunctionalhexadecimalforlonguncprogramtoramruncilanbieitdeslipeiminconvertingasmntpsjpackadesfuncagemeintoproackbinxasatpackisimefunctionalityandarrtrtsvassthavprndonogro


More Tutorials from this section

Ask Questions?    Discuss: Convert Hexadecimal into Binary and Long   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.