public class Main {
public static void main(String[] args) {
String m =Integer.toBinaryString(120);
System.out.println(m);
int ss=Integer.valueOf(m,2);
ss&=ss-1;
System.out.println(ss);
String t =Integer.toBinaryString(ss);
System.out.println(t);
}
}
本文提供了一个Java程序示例,演示了如何将整数转换为二进制字符串,并通过位运算实现特定操作。具体步骤包括:1. 使用`Integer.toBinaryString()`方法将整数120转换为二进制字符串;2. 利用`Integer.valueOf()`方法将二进制字符串转换回整数;3. 执行按位与运算(`&`),并输出结果。
197

被折叠的 条评论
为什么被折叠?



