Skip to content

Commit

Permalink
feat(binary): add shiftRL()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Dec 16, 2021
1 parent 1ba92c6 commit 804565e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/binary/src/rotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ export const rotateLeft = (x: number, n: Bit) =>
*/
export const rotateRight = (x: number, n: Bit) =>
((x >>> n) | (x << (32 - n))) >>> 0;

/**
* Shifts `x` by `n` bits left or right. If `n` >= 0, the value will be `>>>`
* shifted to right, if `n` < 0 the value will be shifted left.
*
* @param x
* @param n
*/
export const shiftRL = (x: number, n: number) => (n < 0 ? x << -n : x >>> n);

0 comments on commit 804565e

Please sign in to comment.