# How to Convert Decimal to Binary to Hex to Octal System in Java?

0
23
• 1
•
•
•
•
•
•
•
•
•
1
Share

 Convert Decimal to Binary to Hex to Octal System

## Decimal to Binary to hex to octal system converter in Java

I have used library functions to convert it.Refer Integer class for for more method.I have also coded without using Library function here.

### The code for Decimal to Binary to Hex to Octal System conversion:

public class DataConversion {
public static void main(String[] args) {
String userNumber = null;
userNumber = JOptionPane.showInputDialog(null,
JOptionPane.QUESTION_MESSAGE);
int in = Integer.parseInt(userNumber );

System.out.println(“Integer: ” + in );
//integer to binary
String by = Integer.toBinaryString( in );
System.out.println(“Byte: ” + by);
String hex = Integer.toHexString( in );
System.out.println(“Hexa decimal: ” + hex);
//integer to octal
String oct = Integer.toOctalString( in );
System.out.println(“Octal: ” + oct);
}
}

Don't miss out!

Receive top technical news, lesson ideas, travel tips and more!

Give it a try. You can unsubscribe at any time.

• 1
•
•
•
•
•
•
•
•
•
1
Share
Next articleFactor Calculation in java
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on [email protected]