Open In App

Scala Int toBinaryString() method with example

Last Updated : 30 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads