帮忙解释 if(((1 << j) & i) != 0) 是什么意思 谢谢!!!

guozhencai 2005-09-21 10:08:11
public class OperPromotionDemo{

public static void printIntBinary(String s, int i) {
System.out.println(s + ", 整数: " + i + ", 二进制: ");
System.out.print(" ");
for(int j = 31; j >= 0; j--)
if(((1 << j) & i) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
}

public static void printByteBinary(String s, int i) {
System.out.println(s + ", 整数: " + i + ", 二进制: ");
System.out.print(" ");
for(int j = 7; j >= 0; j--)
if(((1 << j) & i) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
}

public static void main(String arg[]){
byte a = 10;
byte b = 20;
// byte c = a + b; //加法操作返回的类型最小为四字节整数

int d = 0XFFFE;
long e = 0XFF;
// int a = d + e; //加法操作中的最大数据类型为long,运算结果为long


byte f = 1;
printIntBinary("f + d = ",f + d);

f = 1;
f += d;
printByteBinary("f+=d = ",f);

}
}
帮忙解释 if(((1 << j) & i) != 0) 是什么意思 谢谢!!!
...全文
413 2 打赏 收藏 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dabuniu1846 2005-09-21
  • 打赏
  • 举报
回复
将1左移j位,得到的值与i进行“&”,判断结果是否!=0
super_zzw 2005-09-21
  • 打赏
  • 举报
回复
判断i的第j位是否为2进制0

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧