toBinary static method
Converts a BigInt value to a binary string with optional zero padding.
This method converts a given BigInt value to its binary representation as a string.
Optionally, you can specify the desired bit length by providing zeroPadBitLen
. If provided,
the method will pad the binary string with leading zeros to reach the specified bit length.
Parameters:
value
: The BigInt value to be converted to binary.zeroPadBitLen
: The desired bit length for the binary representation (optional).
Returns:
A binary string representation of the value
, possibly zero-padded.
This method is useful for converting BigInt values to binary strings for various applications.
Implementation
static String toBinary(BigInt value, int zeroPadBitLen) {
String binaryStr = value.toRadixString(2);
if (zeroPadBitLen > 0) {
return binaryStr.padLeft(zeroPadBitLen, '0');
} else {
return binaryStr;
}
}