Created
January 11, 2016 15:48
-
-
Save villavic/3a2b6c3751728daa07f2 to your computer and use it in GitHub Desktop.
A testcase.
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> /* printf */ | |
#include <inttypes.h> /* uint32_t */ | |
#include <stdlib.h> /* atoi */ | |
typedef uint32_t u32; | |
char* itoab2(u32 val){ | |
static char buf[33] = {0}; | |
int i; | |
if (val == 0) return (char *)"0"; | |
for(i=32; val && i; --i) { | |
buf[i] = '0' + (val & 1); | |
val >>= 1; | |
} | |
return &buf[i+1]; | |
} | |
#define prval(a,b) printf("%10s=%#016x\t[0b%s]\n", a, b, itoab2(b)); | |
int main(int argc, char *argv[]) | |
{ | |
u32 res, mod, fshift, sshift, comp, tshift, test; | |
u32 bv = atoi(argv[1]); | |
mod = bv % 16; | |
prval("divmod", mod); | |
fshift = mod << 1; | |
prval("1st shift", fshift); | |
sshift = 3 << fshift; | |
prval("2nd shift", sshift); | |
comp = ~sshift; | |
prval("complement", comp); | |
tshift = 3 << comp; | |
prval("3rd shift", tshift); | |
res = ~tshift; | |
prval("result", res); | |
test = (~(3<<(~(3<<((bv%16)<<1))))); | |
prval("test", test); | |
test = (~(3U<<(~(3U<<((26%16)<<1U))))); | |
prval("testU", test); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment