Skip to content

Instantly share code, notes, and snippets.

@igrek8
Last active December 24, 2016 11:01
Show Gist options
  • Select an option

  • Save igrek8/61db4f434626ed06f87587433925d594 to your computer and use it in GitHub Desktop.

Select an option

Save igrek8/61db4f434626ed06f87587433925d594 to your computer and use it in GitHub Desktop.
nodejs simple class for bitwise ops
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