bitlengthInBytes static method

int bitlengthInBytes(
  1. int val
)

Calculates the number of bytes required to represent the bit length of an integer value.

val The integer value for which to calculate the bit length in bytes. Returns the number of bytes required to represent the bit length of the integer value.

Implementation

static int bitlengthInBytes(int val) {
  int bitlength = val.bitLength;
  if (bitlength == 0) return 1;
  if (val.isNegative) {
    bitlength += 1;
  }
  return (bitlength + 7) ~/ 8;
}