是什么(X ^为0x1)!= 0是什么意思? [英] What does (x ^ 0x1) != 0 mean?

查看:369
本文介绍了是什么(X ^为0x1)!= 0是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到下面的code片段来

I came across the following code snippet

if( 0 != ( x ^ 0x1 ) )
     encode( x, m );

这是什么 X ^为0x1 是什么意思?这是一些标准的技术?

What does x ^ 0x1 mean? Is this some standard technique?

推荐答案

XOR操作( X ^为0x1 )反转位0。因此除权pression有效是指:如果x的0位是0,或者x的任何其他位为1,则前pression为真

The XOR operation (x ^ 0x1) inverts bit 0. So the expression effectively means: if bit 0 of x is 0, or any other bit of x is 1, then the expression is true.

相反除权pression是假的如果x == 1。

Conversely the expression is false if x == 1.

因此​​,试验是一样的:

So the test is the same as:

if (x != 1)

和因此(可以说)不必要的混淆。

and is therefore (arguably) unnecessarily obfuscated.

这篇关于是什么(X ^为0x1)!= 0是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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