Great example!
Small bitwise logic correction to JonnyMac's demo code, the negative value detection and conversion should be something like this:
if (inVal > 0xFF) // if negative
inVal |= 0xFF00; // extend sign bits
return int(inVal);