Last active
December 24, 2016 11:01
-
-
Save igrek8/61db4f434626ed06f87587433925d594 to your computer and use it in GitHub Desktop.
nodejs simple class for bitwise ops
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
| export class Bitwise { | |
| private _i: number; | |
| constructor(value: number) { | |
| this._i = value; | |
| } | |
| test(mask = 0x01) { | |
| return (mask ^ this._i) === 0; | |
| } | |
| set(mask = 0x01) { | |
| this._i = this._i | mask; | |
| return this; | |
| } | |
| get(mask = 0x01) { | |
| return this._i & mask; | |
| } | |
| get value() { | |
| return this._i; | |
| } | |
| reset(mask = 0x01) { | |
| this._i = this._i & ~(mask); | |
| return this; | |
| } | |
| toggle(mask = 0x01) { | |
| this.test(mask) ? | |
| this.reset(mask) : this.set(mask); | |
| return this; | |
| } | |
| } | |
| new Bitwise(0b000100).test(2); // # true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment