parseByte static method

Byte parseByte(
  1. String str, [
  2. int radix = 10
])

Parses a string to a Byte representing a single byte value.

The str parameter is parsed as an integer in the specified radix.

Example:

final decimal = Byte.parseByte('42');        // 42
final hex = Byte.parseByte('FF', 16);        // -1 (255 as signed)
final binary = Byte.parseByte('1010', 2);    // 10
final negative = Byte.parseByte('-128');     // -128

Throws InvalidFormatException if the string cannot be parsed. Throws InvalidArgumentException if the parsed value is outside byte range.

Implementation

static Byte parseByte(String str, [int radix = 10]) {
  final parsed = int.parse(str, radix: radix);

  // Convert to signed 8-bit if needed
  final signed = parsed > MAX_VALUE ? parsed - 256 : parsed;
  return Byte(signed);
}