Skip to content

Commit

Permalink
feat(binary): add MSB_BITS8/16/32 LUTs
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Feb 7, 2021
1 parent ed66a64 commit e0eb47b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/binary/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
const defBits = (n: number) =>
new Array(n).fill(0).map((_, i) => 1 << (n - 1 - i));
/**
* 8bit values in MSB order (i.e. MSB_BITS[0] = 0x80)
*/
export const MSB_BITS8 = defBits(8);

/**
* 16bit values in MSB order (i.e. MSB_BITS[0] = 0x8000)
*/
export const MSB_BITS16 = defBits(16);

/**
* 32bit values in MSB order (i.e. MSB_BITS[0] = 0x80000000)
*/
export const MSB_BITS32 = defBits(32);

export const MASKS = new Array(33).fill(0).map((_, i) => Math.pow(2, i) - 1);

0 comments on commit e0eb47b

Please sign in to comment.