Header Ads

Decimal to Binary to hex to octal system converter :: How I coded It




Decimal to Binary to hex to octal system converter

I have used library functions to convert it. But I am also writing the actual code. So watch this space for more.


public class DataConversion{
  public static void main(String[] args)
 {
  String userName = null;
  userName = JOptionPane.showInputDialog(null,
 "What is your Number?",
 "Enter your Number",
 JOptionPane.QUESTION_MESSAGE);
 int in=Integer.parseInt(userName);

  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);
  }
}
Powered by Blogger.