int8 function

int int8(
  1. int value
)

Implementation

int int8(int value) {
  // Mask to 8-bit unsigned integer
  int maskedValue = value & 0xFF;

  // Check if the value is larger than the max int8_t range
  if (maskedValue > 0x7F) {
    // Convert to a negative int8 by subtracting 2^8
    return maskedValue - 0x100;
  } else {
    // Return as is if it's within the int8 range
    return maskedValue;
  }
}