int32 function

int int32(
  1. int value
)

Implementation

int int32(int value) {
  // Mask to 32-bit unsigned integer
  int maskedValue = value & 0xFFFFFFFF;

  // Check if the value is larger than the max int32_t range
  if (maskedValue > 0x7FFFFFFF) {
    // Convert to a negative int32 by subtracting 2^32
    return maskedValue - 0x100000000;
  } else {
    // Return as is if it's within the int32 range
    return maskedValue;
  }
}