signedRightShift method

int signedRightShift(
  1. int n,
  2. int bitWidth
)

Returns this right-shifted by n bytes assuming bitWidth.

This is intended to be roughly equivalent to JavaScript's >> operator.

NOTE: bitWidth is not validated. See Integral.signedRightShift.

Implementation

int signedRightShift(int n, int bitWidth) {
  final padding = msb(bitWidth) ? 2.pow(n) - 1 : 0;
  return (padding << (bitWidth - n)) | (this >> n);
}