String sText = "";
Integer iValue;
String sValue = "";
/* -- convert to dec */
iValue = Integer.parseInt( "100", 10 );
sText += "dec(100) to dec = " + iValue.toString() + "\n";
iValue = Integer.parseInt( "100", 2 );
sText += "bin(100) to dec = " + iValue.toString() + "\n";
iValue = Integer.parseInt( "100", 16 );
sText += "hex(100) to dec = " + iValue.toString() + "\n";
iValue = Integer.parseInt( "ff", 16 );
sText += "hex(ff) to dec = " + iValue.toString() + "\n";
/* result */
memo.setText( sText );
Output: Microsoft AX 2012, X++, C#, SQL server, SSRS, Java, JavaFX, Oracle, PL/SQL, Delphi - codes examples, step-by-step tutorials, experiences.
Friday, March 9, 2018
JAVA - How convert binary, hex, octal etc. to decimal
For converting from binary, hexadecimal, octal etc. to decimal, use function Integer.parseInt(). Second parameter is base.
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment