The toBinaryString() method is utilized to return the binary form of the specified integer value.
Method Definition: def toBinaryString: String
Return Type: It returns the binary form of the specified integer value.
Example #1:
// Scala program of Int toBinaryString() // method // Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Applying toBinaryString() method
val result = ( 5 ).toBinaryString
// Displays output
println(result)
}
} |
Output:
101
Example #2:
// Scala program of Int toBinaryString() // method // Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Applying toBinaryString() method
val result = ( 15 ).toBinaryString
// Displays output
println(result)
}
} |
Output:
1111