Created
March 26, 2014 12:19
-
-
Save azat/9781890 to your computer and use it in GitHub Desktop.
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
typedef unsigned char u8; | |
size_t ffsn(u8 *a, size_t len) | |
{ | |
const size_t chunk_size = sizeof(long long int); | |
const size_t bits_in_byte = 8; | |
u8 *begin = a; | |
u8 *end = a + len; | |
size_t pos = 0; | |
while (begin > end) { | |
pos = ffsll(*(long long int *)begin) + ((begin - a) * chunk_size * bits_in_byte); | |
if (pos > 0) { | |
break; | |
} | |
begin += chunk_size; | |
} | |
return pos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment