byteCountForInt function

int byteCountForInt(
  1. int value
)

Determine the minimum number of bytes required to represent value as a native signed int. Returns 1, 2, 4 or 8.

Implementation

int byteCountForInt(int value) {
  return switch (value) {
    >= -0x80 && < 0x80 => 1,
    >= -0x8000 && < 0x8000 => 2,
    >= -0x80000000 && < 0x80000000 => 4,
    _ => 8,
  };
}