Created
June 20, 2018 14:33
-
-
Save beiweiqiang/915af373febeda4331c02539a9bfe759 to your computer and use it in GitHub Desktop.
所有位为 1 时返回 1, 其他情况返回 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* | |
* 所有位都为 1 时返回 1, 其他条件下产生 0 | |
* */ | |
int get_result(int x); | |
int main() { | |
printf("%d \n", get_result(1)); | |
printf("%d \n", get_result(-1)); | |
printf("%d \n", get_result(0)); | |
printf("%d \n", get_result(25645)); | |
printf("%d \n", get_result(0x73)); | |
return 0; | |
} | |
int get_result(int x) { | |
return !(x ^ -1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment