Skip to Content

Convert decimal integer to binary number example

  1. /*
  2.         Convert decimal integer to binary number example.
  3.         This example shows how to convert int to binary number using
  4.         toBinaryString method of Integer wrapper class.
  5. */
  6.  
  7. public class ConvertIntToBinaryExample {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 int i = 56;
  12.                
  13.                 String strBinaryNumber = Integer.toBinaryString(i);
  14.                
  15.                 System.out.println("Convert decimal number to binary number example");
  16.                 System.out.println("Binary value of " + i + " is " + strBinaryNumber);
  17.                                                        
  18.         }
  19. }
  20.  
  21. /*
  22. Output would be
  23. Convert decimal number to binary number example
  24. Binary value of 56 is 111000
  25. */