formating/bytes_num_formating
library
Functions
-
binaryToByte(String binary)
→ int
-
Convert a binary string to an integer.
This function takes a binary string 'binary' and converts it into an integer.
It uses the 'int.parse' method with a radix of 2 to interpret the binary string.
The resulting integer represents the value of the binary string.
-
bytesListEqual(List<int>? a, List<int>? b)
→ bool
-
Compare two lists of bytes for equality.
This function compares two lists of bytes 'a' and 'b' for equality. It returns true
if the lists are equal (including null check), false if they have different lengths
or contain different byte values, and true if the lists reference the same object.
-
bytesToBinary(Uint8List bytes)
→ String
-
Convert a Uint8List of bytes to a binary string.
This function takes a Uint8List 'bytes' and converts it into a binary string.
It maps each byte in the list to its binary representation with 8 bits, left-padded
with zeros if needed. Then, it concatenates these binary representations to form
the resulting binary string.
The returned string represents the binary data of the input bytes.
-
bytesToHex(List<int> bytes)
→ String
-
Convert a list of integers (bytes) to a hexadecimal string representation.
This function takes a List of integers and returns a string containing
the hexadecimal representation of the bytes.
-
convertBits(List<int> data, int fromBits, int toBits, {bool pad = true})
→ List<int>?
-
Convert a list of integers from one bit size to another.
This function takes a list of integers, 'data', and converts them from a given
'fromBits' size to a 'toBits' size, optionally padding the output list.
It returns a new list of integers with the converted values or null if conversion
is not possible due to invalid input.
-
decodeBigInt(List<int> bytes)
→ BigInt
-
Decode a list of integers (bytes) into a BigInt.
This function takes a List of integers representing bytes
and converts them into a BigInt, considering byte order.
-
encodeBigInt(BigInt number)
→ Uint8List
-
Encode a BigInt into a Uint8List.
This function takes a BigInt integer and encodes it into a Uint8List
representation, considering necessary padding and byte order.
-
hexToBytes(String hexStr)
→ Uint8List
-
Convert a hexadecimal string to a Uint8List.
This function takes a hexadecimal string 'hexStr', removes the '0x' prefix if present,
and converts it into a Uint8List containing the corresponding byte values.
It returns the Uint8List representation of the hexadecimal string.
-
intFromBytes(List<int> bytes, Endian endian)
→ int
-
Convert a list of bytes to an integer with the specified endianness.
This function takes a list of bytes 'bytes' and an 'endian' parameter indicating
the byte order (Endian.little or Endian.big), and converts the bytes into an integer.
It supports byte lengths of 1, 2, and 4 bytes, and throws an error for unsupported lengths.
If 'bytes' is empty, it raises an ArgumentError.
-
packUint32BE(int value)
→ Uint8List
-
Pack a 32-bit integer into a Big-Endian (BE) Uint8List.
This function takes a 32-bit integer 'value' and packs it into a Uint8List
in Big-Endian (BE) format, where the most significant byte is stored at the
lowest index and the least significant byte at the highest index.
It returns the resulting Uint8List representation of the integer.
-
strip0x(String hex)
→ String
-
Strip the '0x' prefix from a hexadecimal string.
This function takes a hexadecimal string 'hex' and removes the '0x' prefix
if it exists. It returns the string with the prefix removed or the original
string if no prefix is present.