Skip to content

@halitalptekin /bitget.c
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
getting bit value function inspired by duff's device
#define bitGet(v, n) ((v >> n) & 1)
int bitGet(int v, int n){
switch(n - 1){
case 7: v >>= 1;
case 6: v >>= 1;
case 5: v >>= 1;
case 4: v >>= 1;
case 3: v >>= 1;
case 2: v >>= 1;
case 1: v >>= 1;
case 0: v >>= 1; break;
}
return v & 1;
}
int bitGet(int v, int n){
switch(n - 1){
case 1: v >>= 1;
case 0: v >>= 1; break;
default: n > 0 ? bitGet(v >> 1, n - 1) : bitGet( v >> 1, n + 1);
}
return v & 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.