Created
November 29, 2014 11:36
-
-
Save nyuichi/e8d256fc5ad0ab53a3e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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