Open In App
Related Articles

Java lang.Integer.toBinaryString() method

Improve Article
Save Article
Like Article

The java.lang.Integer.toBinaryString() method returns a string representation of the integer argument as an unsigned integer in base 2. It accepts an argument in Int data-type and returns the corresponding binary string.


public static String toBinaryString(int num)

Parameter : The function accepts a single mandatory parameter num 
num - This parameter specifies the number to be converted to binary string. 
It is of int data-type 

Return Value: This function returns the string representation of the unsigned Integer value represented by the argument in binary (base 2).

Input : 10 
Output : 1010 

Input : 9
Output : 1001 

// Java program to demonstrate
// java.lang.Integer.toBinaryString() method
import java.lang.Math;
class Gfg1 {
    // driver code
    public static void main(String args[])
        int l = 10;
        // returns the string representation of the unsigned int value
        // represented by the argument in binary (base 2)
        System.out.println("Binary is " + Integer.toBinaryString(l));
        l = 9;
        System.out.println("Binary is " + Integer.toBinaryString(l));


Binary is 1010
Binary is 1001
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 05 Dec, 2018
Like Article
Save Article
Similar Reads
Complete Tutorials