Java is a high-level, object-oriented programming language created by Sun Microsystems. In addition to allowing programs to define their own data types, or "classes," Java includes a collection of predefined types. When a numerical value is expressed in a base different than 10, or "decimal," you need to parse that value into one of Java's numerical types. In particular, you can convert binary (base 2) values to decimal using methods included in the standard Java platform.
Obtain the value represented in binary, and store the binary representation in a string. This sample code stores the binary representation of 192:
String binNumber = "11000000";
Convert the string to an integer using the built-in parseInt() method, as in this sample code:
int number = Integer.parseInt(binNumber,2);
Generate the decimal representation of the number, as in this sample code:
String decNumber = String.format("%d",number);
For the example, the string "decNumber" will contain the value "192."
- Photo Credit Jupiterimages/Photos.com/Getty Images
How to Run Hex Editor on a PS3 Console
PS3 (PlayStation 3) software can be edited with the use of a hexadecimal (hex) editor, an additional software program that lets users...
How to Convert Paint Colors to Hex Color Code
Your eyes are remarkable optical instruments that can detect millions of colors. Paint programs can work with them using color models such...
Changing Percentages to Decimals
Percentages can be turned into decimals by turning the percentage into a fraction, dividing the top number by the bottom number and...