I am trying to convert decimals, (0.05, -0.28, 25.00, etc), to a 17-bit 2's complement Signed Number. The parameter data I am sending is SysEX Midi Data (to some external Synthesizer). The data parameters are composed of 3 bytes.
For example, the example given is as follows:
- The parameter data to set the value to -0.02 is (07 7F 70) (Data2,Data1,Data0)
I was wondering if anyone could give me guidance for doing this in Java, here are the specifications I am going off of:
- The parameter data is a 17-bit number 2’s complement signed number.
data2= Mix channel number and most significant bits (bits 14-16) of parameter’s data (with the format 0xxx xyyy, where xxxx is the mix channel number (0-15) and yyy are the uppermost bits (bits 14-16) of the parameter data.)
data1= Bits 7-13 of parameter’s data
- data0= Least significant bits (bits 0-6) of parameter’s data
So, here is what I am able to assume so far:
- The 3 bytes is composed of 17 bits, + the 4 bits for sending #'s 0-15 (The Mix Channel)
- The 17th bit is the signing bit?
- The signing bit only needs to be set if It's a negative number, and in which that case needs to be formatted w/ 2's complement
- The highest bit for each parameters data byte is set to 0
With all this in mind, can someone help me understand, post, or help me write a function to format this 17-bit number from a signed decimal value? Binary Bit Adding / Subtracting In Java, Two's Complements, etc...It would be greatly appreciated it anyone has any example functions, or explanations!