numberToHex function

String numberToHex(
  1. dynamic number,
  2. {bool pad = false,
  3. bool include0x = false,
  4. int forcePadLen}
)

Implementation

String numberToHex(dynamic number,
    {bool pad = false, bool include0x = false, int forcePadLen}) {
  String toHexSimple() {
    if (number is int) {
      return number.toRadixString(16);
    } else if (number is BigInt) {
      return number.toRadixString(16);
    } else {
      throw TypeError();
    }
  }

  var hexString = toHexSimple();
  if (pad && !hexString.length.isEven) hexString = "0$hexString";
  if (forcePadLen != null) hexString = hexString.padLeft(forcePadLen, "0");
  if (include0x) hexString = "0x$hexString";

  return hexString;
}