Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Convert Hexadecimal into Binary and Long

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

                         

» View all related tutorials
Related Tags: c convert io help this program to learn ram ear e il section in converting m ps pro s is

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

5 comments so far (
post your own) View All Comments Latest 10 Comments:

int i = Integer.parseInt(hex,16);

to include 0-F, not just 0-9

Posted by Sultan on Sunday, 12.14.08 @ 00:53am | #82730

Missing values A-F as input. 0-9 works just fine though.

Posted by Sultan on Sunday, 12.14.08 @ 00:41am | #82729

i want to learn more about java programming.

Posted by carlofano on Wednesday, 10.15.08 @ 10:12am | #81089

This program is good, but i have problem to convert long type data into hexadecimal, if anyone know please send me the information. Thanks

Posted by Supriyanto on Monday, 08.11.08 @ 06:24am | #72190

my problem is little bit different.My input system is 47:20:57:EF:EE:31
and out put pattren is reverse of actual binary out put 11100010 ...................

Posted by Md.Rafiqul Islam on Tuesday, 08.7.07 @ 11:09am | #22834

 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.