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

    0
    37
    Spread the love
    • 1
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
      1
      Share

    Convert Decimal to Binary to Hex to Octal System
    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,
    “What is your Number?”,
    “Enter your Number”,
    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);
    //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);
    }
    }

    Don't miss out!
    Subscribe To Newsletter

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

    Invalid email address
    Give it a try. You can unsubscribe at any time.

    Spread the love
    • 1
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
      1
      Share

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here