16 bit to 8 bit
ryanww
Posts: 196
I would like an example of converting from an 8 bit integer to a 16 bit integer and vice versa. I just have to convert a level back and forth.
Thanks,
Ryan
Thanks,
Ryan
0
Comments
No conversion needed...
Example:
LEVEL_EVENT [dvBkStoreG3Web,1] //Inside Master Fader
{
SEND_STRING dvSymnetBS,"'CS 421 ',ITOA("(LEVEL.VALUE)16 bit"),$0D"
SYM_CONTROL[421].POSITION = (LEVEL.VALUE)16bit
}
SEND_LEVEL dvBkStoreG3Web,1,(SYM_CONTROL[421].POSITION)8 bit //Inside Level
Simple formula that works for all ratio conversions. Does not matter if your going from a large range to a smaller range, or vice versus, this formula works... The only rub is that the ranges have to be zero to x. If they are not you need to subtract or add to make the ranges 0 to x.
answer = ((max_converted_value * current_value) / max_current_value)
// coverting to a 0 - 65535 range,starting with a 0 to 255 range;
answer = ((65535 * 127) / 255);
// coverting to a 0 - 255 range, starting with a 0 to 65535 range;
answer = ((255 * 32767) / 65535);
// coverting to a 0 -255 range, starting with a -100 to 20 range;
answer = (255 * (current_value + 100)) / 120);
// coverting to a 0 -255 range, starting with a 20 to 80 range;
answer = (255 * (current_value - 20)) / 60);
Since the processor can handle a LONG - 32bit integer I would assume that the operation (65535 * 127) would not overflow the internal operation of the processor. But what if...
I can not think of a real application, but what if you wanted to end up with a range from 0 - 4294967295 (FFFFFFFF) would the initial operation of (4294967295 * 127) overflow the internal operation of the processor? what is the limit of the processor's mathematical operations?
// So this should be true, but netlinx will keep the answer under 32 bits
$FFFFFFFF = (($FFFFFFFF * 2) / 2))
// but netlinx does this
FFFFFFFE = ($FFFFFFFF * 2);
7FFFFFFF = ($FFFFFFE / 2);
// so this is the answer, its wrong, but the answer none the less.
$7FFFFFFF = (($FFFFFFFF * 2) / 2))