How to Convert Binary to Decimal in Java

Written by jonah quant
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert Binary to Decimal in Java
You can convert binary values to their decimal equivalents in Java. (Jupiterimages/ Images)

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


  1. 1

    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";

  2. 2

    Convert the string to an integer using the built-in parseInt() method, as in this sample code:

    int number = Integer.parseInt(bin Number,2);

  3. 3

    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."

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.