BitOperations class

Provides bit-level operations and conversions for byte values.

This class offers granular bit manipulation and querying capabilities, useful for network protocols, binary data handling, and low-level operations.

Example:

final size = ByteConverter.fromKiloBytes(1);
print(size.bitOps.totalBits);     // 8000
print(size.bitOps.kilobits);      // 8.0
print(size.bitOps.megabits);      // 0.008
print(size.bitOps.isPowerOfTwo);  // false

Constructors

BitOperations(ByteConverter _converter)
Creates a BitOperations instance for the given ByteConverter.
const

Properties

asBigInt → BigInt
Total bits as a BigInt (for very large values).
no setter
bitLength → int
The minimum number of bits needed to represent this value.
no setter
gibibits → double
Bits in gibibits (1 Gib = 1,073,741,824 bits).
no setter
gigabits → double
Bits in gigabits (1 Gb = 1,000,000,000 bits).
no setter
hashCode → int
The hash code for this object.
no setterinherited
isByteAligned → bool
Whether the bit count is divisible by 8 (byte-aligned).
no setter
isDoubleWordAligned → bool
Whether the byte count is double-word aligned (8 bytes / 64 bits).
no setter
isL1CacheAligned → bool
Checks if this size is aligned to L1 cache-line boundary (64 bytes).
no setter
isL2CacheAligned → bool
Checks if this size is aligned to L2 cache-line boundary (128 bytes).
no setter
isL3CacheAligned → bool
Checks if this size is aligned to L3 cache-line boundary (256 bytes).
no setter
isPowerOfTwo → bool
Whether the byte count is a power of two.
no setter
isWordAligned → bool
Whether the byte count is word-aligned (divisible by 4 bytes / 32 bits).
no setter
kibibits → double
Bits in kibibits (1 Kib = 1024 bits).
no setter
kilobits → double
Bits in kilobits (1 kb = 1000 bits).
no setter
leadingZeroBits → int
The number of leading zero bits in the binary representation.
no setter
mebibits → double
Bits in mebibits (1 Mib = 1,048,576 bits).
no setter
megabits → double
Bits in megabits (1 Mb = 1,000,000 bits).
no setter
nextPowerOfTwo → ByteConverter
Rounds up to the next power of two.
no setter
popCount → int
The number of set bits (1s) in the binary representation.
no setter
prevPowerOfTwo → ByteConverter
Rounds down to the previous power of two.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
totalBits → int
Total number of bits.
no setter
trailingZeroBits → int
The number of trailing zero bits in the binary representation.
no setter

Methods

alignDownTo(int alignment) → ByteConverter
Aligns down to the specified alignment.
alignDownToL1CacheLine() → ByteConverter
Aligns down to the previous L1 cache-line boundary (64 bytes).
alignDownToL2CacheLine() → ByteConverter
Aligns down to the previous L2 cache-line boundary (128 bytes).
alignDownToL3CacheLine() → ByteConverter
Aligns down to the previous L3 cache-line boundary (256 bytes).
alignTo(int alignment) → ByteConverter
Aligns the byte count up to the specified alignment.
alignToL1CacheLine() → ByteConverter
Aligns up to the next L1 cache-line boundary (64 bytes).
alignToL2CacheLine() → ByteConverter
Aligns up to the next L2 cache-line boundary (128 bytes).
alignToL3CacheLine() → ByteConverter
Aligns up to the next L3 cache-line boundary (256 bytes).
clearBit(int index) → ByteConverter
Returns a new ByteConverter with the bit at index cleared to 0.
humanize({int precision = 2}) → String
Human-readable bit format (e.g., "8 Kb", "1.5 Mb").
humanizeIEC({int precision = 2}) → String
Human-readable bit format using binary prefixes (Kib, Mib, Gib).
isAlignedTo(int alignment) → bool
Returns true if the byte count is aligned to alignment bytes.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setBit(int index) → ByteConverter
Returns a new ByteConverter with the bit at index set to 1.
shiftLeft(int count) → ByteConverter
Returns a new ByteConverter with bits shifted left by count.
shiftRight(int count) → ByteConverter
Returns a new ByteConverter with bits shifted right by count.
testBit(int index) → bool
Tests if the bit at index is set (1).
toBinaryString({int? padTo}) → String
Returns the binary representation of the bits.
toggleBit(int index) → ByteConverter
Returns a new ByteConverter with the bit at index toggled.
toHexString({bool uppercase = false}) → String
Returns the hexadecimal representation of the bytes.
toOctalString() → String
Returns the octal representation of the bytes.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited