【发布时间】:2015-11-18 12:38:35
【问题描述】:
我知道大多数算术运算只能使用按位运算符(Add two integers using only bitwise operators?、Multiplication of two integers using bitwise operators 等...)来完成。
我也知道,如果你有 less 运算符,你可以从中推断出其他运算符 (Sorting only using the less-than operator compared to a trivalue compare function)
所以...如果有一种方法可以仅使用按位运算来实现 less 运算符,我只是好奇。
喜欢:
bool less(int a, int b) { ??? }
为了让它更复杂:
template<typename T> bool less(T a, T b) { ??? }
其中 T 肯定是整数型数字类型(8 ... 64 位)
【问题讨论】:
标签: c++ bit-manipulation bitwise-operators bit