byteCountForUint function

int byteCountForUint(
  1. int value
)

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

Implementation

int byteCountForUint(int value) {
  return switch (value) {
    <= 0xFF => 1,
    <= 0xFFFF => 2,
    <= 0xFFFFFFFF => 4,
    _ => 8,
  };
}