toHexString method

String toHexString()

Returns a hexadecimal string representation of the bytes.

Each byte is represented as a two-digit uppercase hex value.

Example:

final bytes = Byte.fromList([255, 0, 171]);
print(bytes.toHexString());  // 'FF00AB'

final hello = Byte.fromString('Hi');
print(hello.toHexString());  // '4869'

Implementation

String toHexString() {
  return toUnsignedList()
      .map((b) => b.toRadixString(16).toUpperCase().padLeft(2, '0'))
      .join();
}