Scala Int toBinaryString() 方法与示例
toBinaryString()方法用于返回指定整数值的二进制形式。
Method Definition: def toBinaryString: String
Return Type: It returns the binary form of the specified integer value.
示例 #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)
}
}
输出:
101
示例 #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)
}
}
输出:
1111