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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Convert integer type data into binary, octal and hexadecimal 
 

In this section, you will learn how to convert an integer type data into binary, octal and hexadecimal.

 

Convert integer type data into binary, octal and hexadecimal

                         

In this section, you will learn how to convert an integer type data into binary, octal and hexadecimal. The  java.lang package provides the facility for converting the data integer into binary, octal, and hexadecimal. The following program helps you to convert into these. toBinaryString() method converts integer type data into binary, toHexString() method converts integer type into hexadecimal and toOctalString() method converts integer into octal type data. 

Description of code:

toBinaryString(int in):
This is the method that takes an integer type value and returns the string representation of unsigned integer value that will represent the data in binary (base 2).

toHexString(int in):
This is the method that takes an integer type value and converts in hexadecimal or in an unsigned integer (base 16).

toOctalString(int in):
This is the method that takes an integer type value and converts it into octal type data. The octal type data has base 8.

Here is the code of program:

public class DataConversion{
  public static void main(String[] args) {
    System.out.println("Data types conversion example!");
    int in = 50;
    System.out.println("Integer: " + in);
    //integer to binary
    String by = Integer.toBinaryString(in);
    System.out.println("Byte: " + by);
    //integer to hexadecimal
    String hex = Integer.toHexString(in);
    System.out.println("Hexa decimal: " + hex);
    //integer to octal
    String oct = Integer.toOctalString(in);
    System.out.println("Octal: " + oct);
  }
}

Download this example.

Output of program:

C:\vinod\Math_package>javac DataConversion.java

C:\vinod\Math_package>java DataConversion
Data types conversion example!
Integer: 50
Byte: 110010
Hexa decimal: 32
Octal: 62

                         

» View all related tutorials
Related Tags: c com file ide class files stl date time variables static directory io make variable dates sed get ria this

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

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

fantastic!!, but can you assist me to download all the topics in my mail. thanks

Posted by khadijah on Monday, 01.21.08 @ 23:25pm | #45809

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
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

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.