Last active
September 23, 2022 22:57
-
-
Save kinoko87/c1499b1ffc1785ec03a17fb1c2ba55eb to your computer and use it in GitHub Desktop.
A abstract that allows you to use an integer as a bitfield.
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
| abstract Bitfield(Int) from Int to Int | |
| { | |
| inline public function new(num:Int) | |
| { | |
| this = num; | |
| } | |
| public inline function setBit(n:Int) | |
| { | |
| this |= 0x1 << n; | |
| } | |
| public inline function clearBit(n:Int) | |
| { | |
| this &= ~(0x1 << n); | |
| } | |
| @:op([]) | |
| public inline function isBitSet(n:Int):Bool | |
| { | |
| return ((this >> n) & 0x1) == 1; | |
| } | |
| public inline function invertBits(n:Int) | |
| { | |
| this ^= n; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment