Java lang.Integer.toBinaryString() method
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.
Syntax:
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).
Examples:
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)); } } |
Output:
Binary is 1010 Binary is 1001
Recommended Posts:
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java.lang.string.replace() method in Java
- Java.math.BigInteger.probablePrime() method in Java
- Java Clock withZone() method in Java with Examples
- Java.math.BigInteger.modInverse() method in Java
- Java 8 | ArrayDeque removeIf() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


