替换“=="按位运算符 [英] Replacing "==" with bitwise operators

查看:37
本文介绍了替换“=="按位运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅使用位运算符(|、&、~、^、>>、<<)和其他基本运算符如 +、- 和 !,是否可以替换下面的=="?

Using only bitwise operators (|, &, ~, ^, >>, <<) and other basic operators like +, -, and !, is it possible to replace the "==" below?

int equal(int x, int y) {
    return x == y;
}

推荐答案

两个数如果没有差就相等:

Two numbers are equal if there is no difference between them:

int equal(int x, int y){
   return !(x-y);
}

这篇关于替换“=="按位运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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