devxlogo

Converting Base 10 numbers to Binary numbers

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 easier mechanism to achieve the same.

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

*/

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist