Skip to content

Instantly share code, notes, and snippets.

@beiweiqiang
Created June 20, 2018 14:33
Show Gist options
  • Save beiweiqiang/915af373febeda4331c02539a9bfe759 to your computer and use it in GitHub Desktop.
Save beiweiqiang/915af373febeda4331c02539a9bfe759 to your computer and use it in GitHub Desktop.
所有位为 1 时返回 1, 其他情况返回 0
#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