Created
September 26, 2013 06:39
-
-
Save baobao/6710584 to your computer and use it in GitHub Desktop.
指定したbitが0か1かをチェックする
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
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