Skip to content

Instantly share code, notes, and snippets.

@sideb0ard
Created June 15, 2016 16:23
Show Gist options
  • Save sideb0ard/de88bd2cf0da86297912589baf0364aa to your computer and use it in GitHub Desktop.
Save sideb0ard/de88bd2cf0da86297912589baf0364aa to your computer and use it in GitHub Desktop.
bitwise reverse lookup
#include <stdio.h>
int bignumz[16];
int conv_bitz(int num)
{
for ( int i = 0 ; i < 16; i++) {
//printf("Comparing %d with %d\n", num, ( 1 << i));
//printf("AND is %d\n", num & ( 1 << i));
if ( (num & ( 1 << i )) == num ) {
printf("%d is %d\n", num, i);
return i;
}
}
}
int main()
{
for ( int i = 0; i < 16; i++ ) {
bignumz[i] = ( 1 << i );
}
for ( int i = 0; i < 16; i++ ) {
printf("Bitwise %d is %d\n", i, bignumz[i]);
}
printf("====================================\n\n");
for ( int i = 0; i < 16; i++ ) {
conv_bitz(bignumz[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment