算术运算中的按位与
按位 OR(|) 与算术加法 (+) 类似,即 A|B = A+B (如果 A!=B),
例如 2|4 = 6 和 2+4 = 6
这意味着有一种方法可以得到 " OR”通过在算术上下文中进行加法得到结果。
是否有类似的方法通过进行算术运算来获得按位“AND”结果。
即 A&B = aithmetic_op(A,B)
A = 2^k (k=1,2,3,4...)
B = 2^k (k=1,2,3,4...)
谢谢
Bitwise OR(|) is similar to arithmetic addition(+) i.e. A|B = A+B (if A!=B)
Like, 2|4 = 6 and 2+4 = 6
That means there is a way to get "OR" result in by doing addition in arithmetic context.
Is there a similar way to get bitwise "AND" result by doing arithmetic operation.
i.e. A&B = aithmetic_op(A,B)
A = 2^k (k=1,2,3,4...)
B = 2^k (k=1,2,3,4...)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如
OR
类似于+
,AND
类似于*
请注意,这仅适用于单个位(正如您提到的
OR
和+
之间的类比),由于算术进位的影响。Just as
OR
is analogous to+
,AND
is analogous to*
Note that this only works for a single bit (as does the analogy between
OR
and+
that you mention), due to the effects of arithmetic carries.