Created
September 4, 2015 22:50
-
-
Save ironboy/c9fcfb0d0f1637f2c1c2 to your computer and use it in GitHub Desktop.
Bit test in js
This file contains hidden or 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 bit_test(num,bit){ | |
| return ((num>>bit) % 2 != 0) | |
| } | |
| function bit_set(num,bit){ | |
| return num | 1<<bit; | |
| } | |
| function bit_clear(num,bit){ | |
| return num & ~(1<<bit); | |
| } | |
| function bit_toggle(num,bit){ | |
| return bit_test(num,bit)?bit_clear(num,bit):bit_set(num,bit); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment