2015-05-22 by rpcfender@...
Hi
there is a pdf in the files section, SecretBC.pdf that discusses negative numbers.
You can do some negative numbers.
As midi data has to be less than 127 that means it is 7bits only.
If there needs to be a sign bit (bit 6), the the value can only vary from
1 00 0000 to 0 11 1111 or 0 to $3F or -64 to 63
Normally in an 7bit computer subtracting 1 from each line...
63 = 011 1111
..
01 = 000 0001
00 = 000 0000
-01 = 111 1111
-02 = 111 1110
..
-63 = 100 0001
-64 = 100 0000
But you can see there is a big jump between 0 and -1. The BC thinks this is going from 0 to 127 in one step.
But if you could just output bits 0 to 6 you could have bit 7 high in the positive numbers and the you could have a range that made the numbers sequential for the BC to handle. The BC can use 14bit numbers. That is a max range of 0 to $3FFF
63 = 1011 1111 really = 191 ($BF)
..
01 = 1000 0001 = 129
00 = 1000 0000 = 128
-01 = 0111 1111 = 127
-02 = 0111 1110 = 126
..
-63 = 0100 0001 = 65 ($42)
-64 = 0100 0000 = 64 ($40)
So for a range of -63 to 63 set max = 191 ($BF) and min = 66 ($42)
val is the same as val0.6 so bit 7 is removed before it is send as Midi data just as you would want.
If you really need a range of -127 to 127 you can still use this trick but you need an extra bit.
Again normally in an 8bit computer subtracting 1
127= 0111 1111
..
01 = 0000 0001
00 = 0000 0000
-01 = 1111 1111
-02 = 1111 1110
..
-126= 1000 0010
-127= 1000 0001
There is that jump again.
127= 1 0111 1111 (max $17F)
..
01 = 1 0000 0001
00 = 1 0000 0000
-01 = 0 1111 1111
-02 = 0 1111 1110
..
-126= 0 1000 0010
-127= 0 1000 0001 (min $181)
-128= 0 1000 0000 (min $180)
Make the max $17F and the Min $181, but Midi data is 7bits so you need 2 bytes
We have val 0.6 for the lower 7 bits. So we need val7 for bit7, but the BC doesn't have that.
It only has val7.13, but then you would have the extra 'tricky' bit giving the wrong answer.
If your sysex needs 8 bit data values broken up into two 4 bit nibbles then that is possible
val4.7 val0.3
This is the only case for the BC and negative 8bit numbers
All the best
Royce