castToByte function

int castToByte(
  1. int v
)

Implementation

int castToByte(int v) {
  int m = v & 0xFF;
  if (m >= 128){
    // handle two's compliment
    m = -128 + (m - 128);
  }
  return m;
}