Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Mar 10, 2020

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Converting Base 10 Numbers to Binary Numbers

Programming needs vary. You may have a requirement to convert a Base 10 value to binary as part of a complex logic. Java has an easy mechanism to achieve this.

public class Base10ToBinary
{
   public static void main(String args[])
   {
      Base10ToBinary base10ToBinary = new Base10ToBinary();
      base10ToBinary.proceed();
   }
   
   private void proceed()
   {
      int num = 10;

      String binaryNum = Integer.toString(num, 2); 
        System.out.println("Binary value of " + num + " : " + binaryNum); 
   }
}

/*

Expected output:

[root@mypc]# java Base10ToBinary
Binary value of 10 : 1010

*/
M S Sridhar
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
w3.org
eloquentjavascript.net