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.
- Skill level:
Other People Are Reading
Obtain the value represented in binary, and store the binary representation in a string. This sample code stores the binary representation of 192:
String bin Number = "11000000";
Convert the string to an integer using the built-in parseInt() method, as in this sample code:
int number = Integer.parseInt(bin Number,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."
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for