convert64BitListTo8Bit static method

List<int> convert64BitListTo8Bit(
  1. List<int> bitList
)

Returns a list as byte level from bits

CAN encoding requires this as to form the 8 byte message.

Implementation

static List<int> convert64BitListTo8Bit(List<int> bitList) {
  // List to store the 8-bit integers
  List<int> byteList = [];

  // Loop through the bitList in chunks of 8 bits
  for (int i = 0; i < bitList.length; i += 8) {
    int byteValue = 0;

    // Convert the 8-bit slice to a single byte
    var byteValue2 = List.from(bitList.sublist(i,i+8).reversed);
    for (int j = 0; j < 8; j++) {
      byteValue |= (byteValue2[j] << (7 - j));  // Shift to position (7-j)
    }

    byteList.add(byteValue);
  }

  return byteList;
}