我想知道一个数字是否是奇数。我想比较 LSB 而不是使用模数。
int main(int argc, char*argv[])
{
if ( argc >1 ) {
if ( atoi(argv[1]) & 0x1 == 1 )
printf ("odd num \n");
}
return 0;
}
# ./odd 2
# ./odd 3
odd num
# ./odd 22
# ./odd 23
# ./odd 33
odd num
# ./odd 43
# ./odd 52
odd num
# file odd
odd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x56f7eb1e7a35762bd8b786eefb5516a14549fc1f, not stripped