intToBytes static method

List<int> intToBytes(
  1. int value, {
  2. int length = 4,
  3. bool littleEndian = true,
})

Implementation

static List<int> intToBytes(
  int value, {
  int length = 4,
  bool littleEndian = true,
}) {
  List<int> bytes = [];
  if (littleEndian) {
    for (int i = 0; i < length; i++) {
      bytes.add((value >> (i * 8)) & 0xFF);
    }
  } else {
    for (int i = length - 1; i >= 0; i--) {
      bytes.add((value >> (i * 8)) & 0xFF);
    }
  }
  return bytes;
}