Skip to content

Instantly share code, notes, and snippets.

@baobao
Created September 26, 2013 06:39
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 baobao/6710584 to your computer and use it in GitHub Desktop.
Save baobao/6710584 to your computer and use it in GitHub Desktop.
指定したbitが0か1かをチェックする
function checkFlg(keta:uint, value:uint):Boolean
{
if (keta == 0) throw new Error("error");
var checkNum:int = keta > 2 ? Math.pow(2, keta) : keta;
value /= checkNum;
value *= 128;
if (value >= 256)
{
// 8ビットなので256以上は巻き戻る
while (value >= 256)
value -= 256;
}
return value != 0;
}
// ==== sample ==== //
var foo:int = 124;
var flg:Boolean = checkFlg(3, foo);
trace(flg); //
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment