陈述时提供帮助 [英] Help in if statemment

查看:86
本文介绍了陈述时提供帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if(x&1)!= 0


该语句如何工作?
我不明白

if(x & 1) != 0


how does the statement work?
i can''t get it
any help please??

推荐答案

它将检查x的第一位(最低有效位)是否已设置(等于1,而不是0).
只有语法需要方括号括起来:if ((x & 1) != 0) ….

—SA
It checks up if the first (least-significant) bit of x is set (equals to 1, not to 0).
Only the syntax requires brackets around to condition: if ((x & 1) != 0) ….

—SA


这是按位操作.有关更多信息,请参见此处:
http://www.leepoint.net/notes-java/data/expressions/bitops.html [^ ]
因此,x& 1检查是否设置了第一位,x& 2检查是否设置了第二位,依此类推...
This is a bitwise operation. See here for more information:
http://www.leepoint.net/notes-java/data/expressions/bitops.html[^]
So, x&1 checks if the first bit is set, x&2 checks if the second bit is set and so on...


这篇关于陈述时提供帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆