toSigned method

  1. @override
Int64 toSigned(
  1. int width
)

Returns the least significant width bits of this integer, extending the highest retained bit to the sign. This is the same as truncating the value to fit in width bits using an signed 2-s complement representation. The returned value has the same bit value in all positions higher than width.

If the input value fits in width bits without truncation, the result is the same as the input. The minimum width needed to avoid truncation of x is x.bitLength + 1, i.e.

x == x.toSigned(x.bitLength + 1);

Implementation

@override
Int64 toSigned(int width) {
  if (width < 1 || width > 64) throw RangeError.range(width, 1, 64);
  if (width > _BITS01) {
    return Int64._masked(_l, _m, _h.toSigned(width - _BITS01));
  } else if (width > _BITS) {
    int m = _m.toSigned(width - _BITS);
    return m.isNegative
        ? Int64._masked(_l, m, _MASK2)
        : Int64._masked(_l, m, 0); // Masking for type inferrer.
  } else {
    int l = _l.toSigned(width);
    return l.isNegative
        ? Int64._masked(l, _MASK, _MASK2)
        : Int64._masked(l, 0, 0); // Masking for type inferrer.
  }
}