Skip to content

Instantly share code, notes, and snippets.

@rbonghi
Last active August 29, 2015 14:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbonghi/3d65aec5483729713b50 to your computer and use it in GitHub Desktop.
Save rbonghi/3d65aec5483729713b50 to your computer and use it in GitHub Desktop.
How to count a line
#define BIT_LEN 7
float line_value(int line) {
int i;
int value = 0, count = 0;
for(i=0; i < BIT_LEN; ++i) {
int mask = (1 << (i));
if((line & (mask)) == (mask)) {
value += i:
count++;
}
}
return value/count - BIT_LEN/2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment