[JAVA] binary, octal, hexadecimal, decimal between conversions
Decimal turns into 16: integer.tohexstring (int i) decimal into octal integer.tooctalstring (int i) decimal into binary integer.tobinarystring (int i) hexadecimal to decimal integer.valueof ("FFFF"). ToString () octal to decimal integer.valueof ("876", 8). ToString () binary to decimal intege
R.valueof ("0101", 2). ToString () is there any way to directly convert the 2,8,16 into a 10-in-system?
The Java.lang.Integer class parseint (string s, int radix) resolves a string parameter to a signed integer using the cardinality specified by the second argument. Examples from Jdk:parseint ("0") returns 0 parseint ("473", Ten) returns 473 ("0",) parseint 0 returns NT ("-ff") returns-255 parseint ("1100110", 2) returns 102 ("parseint",) 2147483647 returns (" -2147483648", returns-2147483648 parseint ("2147483648",) throws a numberformatexception parseint ("the", throws A numberformatexception parseint ("Kona", throws a NumberFormatException parseint ("Kona",) returns 411787 How to write conversion (two, eight, 16) without algorithm integer.tobinarystring integer.tooctalstring integer.tohexstring case Two public class test{public static void Main (String args[]) {int i=100;
String binstr=integer.tobinarystring (i);
String otcstr=integer.tooctalstring (i);
String hexstr=integer.tohexstring (i);
System.out.println (BINSTR); Example two public class Teststringformat {public static void main (string[] args) {if (args.length = = 0) {Syst
Em.out.println ("Usage:java teststringformat <a number>");
System.exit (0);
Integer factor = integer.valueof (Args[0]);
String s;
s = String.Format ("%d", factor);
System.out.println (s);
s = String.Format ("%x", factor);
System.out.println (s);
s = String.Format ("%o", factor);
System.out.println (s);
Other methods: Integer.tohexstring (your 10 number);
For example String temp = integer.tohexstring (75);
The output TEMP is 4b//input a 10 binary number and converts it into a 16 import java.io.*; public class tohex{public static void Main (String[]args) {int input;//holds an instance of input data//create an input string BufferedReader stri N=new BufferedReader (New InputstreAmreader (system.in));
System.out.println ("Please enter an integer:");
String X=null;
try{X=strin.readline ();
}catch (IOException ex) {ex.printstacktrace ();
} input=integer.parseint (x); System.out.println ("You enter the number is:" +input)//output from the keyboard received the number System.out.println ("Its 16 is:" +integer.tohexstring (input));
Use tohexstring to convert 10 into 16}}