Integral<T extends Integral<T> > class
abstract
Encapsulates a common integral data type of declared size and signs.
These data structures are easier to use than BinaryInt, but come at a cost of needing to box (wrap) int values in a class, and the overhead that comes with that in the Dart and JavaScript VMs, and should be avoided in perf-sensitive code.
You can also extend this class to create a custom implementation:
class Uint3 extends Integral<Uint3> {
// Implement toDebugString(), wrapSafeValue(), and constructors.
}
See Int4 and Uint4 for examples!
WARNING: Do not implement or mix-in this class.
Constructors
- Integral.checked({required int value, required int size, required bool signed})
- Used for implementing sub-types.
- Integral.unchecked({required int value, required int size, required bool signed})
-
An unsafe constructor that does not verify if the values are within range.
const
Properties
- bitsSet → int
-
Returns the number of set bits in value.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- isNegative → bool
-
Returns
true
iff value represents a negative number, elsefalse
.no setter - isPositive → bool
-
Returns
true
iff value represents a positive number, elsefalse
.no setter - msb → bool
-
Returns whether the most-significant-bit in value is set.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → int
-
Numbers of bits in this data type.
final
- value → int
-
Value wrapped by the Integral.
final
Methods
-
bitChunk(
int left, int size) → T -
Returns a new instance with bits in
left
tosize
. -
bitRange(
int left, int right) → T -
Returns a new instance with bits
left
toright
, inclusive. -
clearBit(
int n) → T -
Returns with the
n
th bit from value cleared. -
compareTo(
Integral< Integral> o) → int -
Compares this object to another object.
override
-
getBit(
int n) → int -
Returns the
n
th bit from value. -
isClear(
int n) → bool -
Returns whether the
n
th bit from value is cleared. -
isSet(
int n) → bool -
Returns whether the
n
th bit from value is set. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
replaceBitRange(
int left, int right, int bits) → T -
Returns a new instance with bits
left
toright
, inclusive, replaced. -
rotateRightShift(
int number) → T -
Returns a bit-wise right rotation on value by
number
of bits. -
setBit(
int n) → T -
Returns with the
n
th bit from value set. -
signedRightShift(
int n) → T -
Returns value arithmetically right-shifted
n
bits. -
signExtend(
int startSize) → T - Returns the current value BinaryInt.signExtend-ed to the full size.
-
toBinary(
) → String - Returns value as a binary string representation.
-
toBinaryPadded(
) → String -
Returns value as a binary string representation, padded with
0
's. -
toDebugString(
) → String - Returns a debug-friendly representation of toString.
-
toggleBit(
int n, [bool? v]) → T -
Sets the
n
th bit ifv
istrue
, otherwise clears. -
toString(
) → String -
A string representation of this object.
override
-
wrapSafeValue(
int value) → T -
Implement to create an instance of self around
value
.
Operators
-
operator &(
T other) → T - Bitwise AND operator.
-
operator <(
T other) → bool - Less than comparison.
-
operator <<(
T other) → T - Left-shift operator.
-
operator <=(
T other) → bool - Less than or equal comparison.
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >(
T other) → bool - Greater than comparison.
-
operator >=(
T other) → bool - Greater than or equal comparison.
-
operator >>(
T other) → T - Right-shift operator.
-
operator ^(
T other) → T - Bitwise XOR operator.
-
operator |(
T other) → T - Bitwise OR operator.
-
operator ~(
) → T - Bitwise NOT operator.