int32 Class
An immutable 32-bit signed integer, in the range -2^31, 2^31 - 1
.
Arithmetic operations may overflow in order to maintain this range.
Implements
Constructors
Code new int32.fromInt(int i) #
Constructs an int32 from an int
. Only the low 32 bits of the input
are used.
int32.fromInt(int i) : _i = (i & 0x7fffffff) - (i & 0x80000000);
Code const int32._internal(int i) #
const int32._internal(int i) : _i = i;
Static Methods
Code int32 parseHex(String s) #
Parses a hexadecimal String
and returns an int32.
static int32 parseHex(String s) => parseRadix(s, 16);
Code int32 parseInt(String s) #
Parses a decimal String
and returns an int32.
static int32 parseInt(String s) => new int32.fromInt(Mathx.parseInt(s));
Code int32 parseRadix(String s, int radix) #
Parses a String
in a given
radix between 2 and 16 and returns an
int32.
static int32 parseRadix(String s, int radix) { if ((radix <= 1) || (radix > 16)) { throw "Bad radix: $radix"; } int32 x = ZERO; for (int i = 0; i < s.length; i++) { int c = s.charCodeAt(i); int digit = _decodeHex(c); if (digit < 0 || digit >= radix) { throw new Exception("Non-radix char code: $c"); } x = (x * radix) + digit; } return x; }
Static Fields
Code final int32 MAX_VALUE #
The maximum positive value attainable by an int32, namely 2147483647.
static final int32 MAX_VALUE = const int32._internal(0x7FFFFFFF);
Code int32 MIN_VALUE #
The minimum positive value attainable by an int32, namely -2147483648.
static int32 MIN_VALUE = const int32._internal(0x80000000);
Methods
Code int compareTo(Comparable other) #
int compareTo(Comparable other) { if (other is int64) { return this.toInt64().compareTo(other); } return _i.compareTo(_convert(other)); }
Code int hashCode() #
int hashCode() => _i;
Code bool isEven() #
bool isEven() => (_i & 0x1) == 0;
Code bool isMaxValue() #
bool isMaxValue() => _i == 2147483647;
Code bool isMinValue() #
bool isMinValue() => _i == -2147483648;
Code bool isNegative() #
bool isNegative() => _i < 0;
Code bool isOdd() #
bool isOdd() => (_i & 0x1) == 1;
Code bool isZero() #
bool isZero() => _i == 0;
Code int numberOfLeadingZeros() #
int numberOfLeadingZeros() => _numberOfLeadingZeros(_i);
Code int numberOfTrailingZeros() #
int numberOfTrailingZeros() => _numberOfTrailingZeros(_i);
Code bool operator <=(other) #
bool operator <=(other) { if (other is int64) { return this.toInt64() < other; } return _i <= _convert(other); }
Code bool operator >(other) #
bool operator >(other) { if (other is int64) { return this.toInt64() < other; } return _i > _convert(other); }
Code bool operator ==(other) #
Code int32 operator >>(int n) #
int32 operator >>(int n) { if (n < 0) { throw new IllegalArgumentException("$n"); } n &= 31; int value; if (_i >= 0) { value = _i >> n; } else { value = (_i >> n) | (0xffffffff << (32 - n)); } return new int32.fromInt(value); }
Code int32 operator <<(int n) #
int32 operator <<(int n) { if (n < 0) { throw new IllegalArgumentException("$n"); } n &= 31; return new int32.fromInt(_i << n); }
Code int32 operator ^(other) #
int32 operator ^(other) { if (other is int64) { return (this.toInt64() ^ other).toInt32(); } return new int32.fromInt(_i ^ _convert(other)); }
Code int32 operator |(other) #
int32 operator |(other) { if (other is int64) { return (this.toInt64() | other).toInt32(); } return new int32.fromInt(_i | _convert(other)); }
Code bool operator <(other) #
bool operator <(other) { if (other is int64) { return this.toInt64() < other; } return _i < _convert(other); }
Code int32 operator ~/(other) #
int32 operator ~/(other) { if (other is int64) { // Result will be int32 return (this.toInt64() ~/ other).toInt32(); } return new int32.fromInt(_i ~/ _convert(other)); }
Code int32 operator %(other) #
int32 operator %(other) { if (other is int64) { // Result will be int32 return (this.toInt64() % other).toInt32(); } return new int32.fromInt(_i % _convert(other)); }
Code intx operator *(other) #
intx operator *(other) { if (other is int64) { return this.toInt64() * other; } // TODO(rice) - optimize return (this.toInt64() * other).toInt32(); }
Code int32 operator &(other) #
int32 operator &(other) { if (other is int64) { return (this.toInt64() & other).toInt32(); } return new int32.fromInt(_i & _convert(other)); }
Code intx operator +(other) #
intx operator +(other) { if (other is int64) { return this.toInt64() + other; } return new int32.fromInt(_i + _convert(other)); }
Code bool operator >=(other) #
bool operator >=(other) { if (other is int64) { return this.toInt64() < other; } return _i >= _convert(other); }
Code intx operator -(other) #
intx operator -(other) { if (other is int64) { return this.toInt64() - other; } return new int32.fromInt(_i - _convert(other)); }
Code int32 remainder(other) #
int32 remainder(other) { if (other is int64) { // Result will be int32 int64 t = this.toInt64(); return (t - (t ~/ other) * other).toInt32(); } return this - (this ~/ other) * other; }
Code int32 shiftRightUnsigned(int n) #
int32 shiftRightUnsigned(int n) { if (n < 0) { throw new IllegalArgumentException("$n"); } n &= 31; int value; if (_i >= 0) { value = _i >> n; } else { value = (_i >> n) & ((1 << (32 - n)) - 1); } return new int32.fromInt(value); }
Code List<int> toBytes() #
List<int> toBytes() { List<int> result = new List<int>(4); result[0] = _i & 0xff; result[1] = (_i >> 8) & 0xff; result[2] = (_i >> 16) & 0xff; result[3] = (_i >> 24) & 0xff; return result; }
Code String toHexString() #
String toHexString() => _i.toRadixString(16);
Code int toInt() #
int toInt() => _i;
Code String toRadixString(int radix) #
String toRadixString(int radix) => _i.toRadixString(radix);
Code String toString() #
String toString() => _i.toString();