Skip to content

Instantly share code, notes, and snippets.

@nyuichi
Created November 29, 2014 11:36
Show Gist options
  • Select an option

  • Save nyuichi/e8d256fc5ad0ab53a3e6 to your computer and use it in GitHub Desktop.

Select an option

Save nyuichi/e8d256fc5ad0ab53a3e6 to your computer and use it in GitHub Desktop.
int __and(int a, b) {
int i, x;
x = 0;
for (i = 31; i >= 0; --i) {
x = x << 1;
if (__bitget(a, i) + __bitget(b, i) >= 2) {
x += 1;
}
}
return x;
}
int __or(int a, b) {
int i, x;
x = 0;
for (i = 31; i >= 0; --i) {
x = x << 1;
if (__bitget(a, i) + __bitget(b, i) >= 1) {
x += 1;
}
}
return x;
}
int __not(int a) {
return - a - 1;
}
int __xor(int a, b) {
int i, x;
x = 0;
for (i = 31; i >= 0; --i) {
x = x << 1;
if (__bitget(a, i) + __bitget(b, i) == 1) {
x += 1;
}
}
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment