reverseBytes method

T reverseBytes()

Implementation

T reverseBytes() {
  T result = constructorCallback(0);
  T tmpValue = constructorCallback(value);
  final T one = constructorCallback(1);

  for (int i = 0; i < numberOfBytesRequired * 8; i++) {
    // first shift is useless but otherwise this loop would shift the last
    // bit of result out (when i = 7) - off by one bit error
    result <<= 1;
    result |= tmpValue & one;
    tmpValue >>= 1;
  }

  return result;
}