This question already has answers here:
Converting an int to a binary string representation in Java?
                                
                                    (16个答案)
                                
                        
                                7个月前关闭。
            
                    
假设我有一个像这样初始化的二进制数:

   int y=0b110101;


如何将110101转换为字符串?
我要这样:

String str1 = Integer.toString(y);

System.out.println(str1);


得出结果110101或0b110101,而不是53。

最佳答案

Integer.toBinaryString(y)会为您提供110101,如果需要,您可以在结果前加上0b

09-26 22:57