diff --git a/packages/binary/src/rotate.ts b/packages/binary/src/rotate.ts index 8a48f78c50..dad1aae0cd 100644 --- a/packages/binary/src/rotate.ts +++ b/packages/binary/src/rotate.ts @@ -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);