Skip to content

Instantly share code, notes, and snippets.

@ma34s
Created November 24, 2012 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ma34s/4139462 to your computer and use it in GitHub Desktop.
Save ma34s/4139462 to your computer and use it in GitHub Desktop.
勘違いでしたが・・・
/*
★勘違いしていた仕様について
 「8bitの変数の立っているビット数を求める」
要素数256で8bit単位処理する方が当然早いが、
4bit単位にしているのは、テーブルサイズを抑えるため
 ※組み込みの癖ですので気にせずに
*/
int sample( char a )///[I ] データ
{
const char NUMS[16] =
{
// 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,
};
char a = xx; 
char s = NUMS[a&0xf]+NUMS[(a>>4)&0xf]; //sに立っているビットの数がはいる
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment