爪哇。整型。方法将整数参数的字符串表示形式返回为基数为2的无符号整数。它接受Int数据类型的参数,并返回相应的二进制字符串。
null
语法:
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
返回值: 此函数返回参数以二进制(基数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
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END