Created
October 2, 2017 03:12
-
-
Save ellenia/d91e5594f17d9a36d94cb1efb2840275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//first way | |
//decimal to binary | |
String binaryString = Integer.toBinaryString(number); | |
System.out.println("decimal to binary: " + binaryString); | |
//decimal to octal | |
String octalString = Integer.toOctalString(number); | |
System.out.println("decimal to octal: " + octalString); | |
//decimal to hexadecimal | |
String hexString = Integer.toHexString(number); | |
System.out.println("decimal to hexadecimal: " + hexString); | |
//second way | |
binaryString = Integer.toString(number,2); | |
System.out.println("decimal to binary using Integer.toString: " + binaryString); | |
//decimal to octal | |
octalString = Integer.toString(number,8); | |
System.out.println("decimal to octal using Integer.toString: " + octalString); | |
//decimal to hexadecimal | |
hexString = Integer.toString(number,16); | |
System.out.println("decimal to hexadecimal using Integer.toString: " + hexString); | |
//javarevisited.blogspot.com/2011/10/convert-decimal-binary-octal-java.html#ixzz4uJhRMI1l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment