Conversion decimal to hex for Sysex output
I'm trying to convert some decimal number to hex format.It's between 0-1023.The result must be two bytes :
Decimal : 523
Hex : 02 0B
How can i do this in Max?
Thanks
i believe [sxformat] does this for you.
It didn't.i've checked it with putting a print object to the outlet of sxformat.It still gives one number that between 0 to 1023
I also checked with capture object.Same thing
sxformat 240 67 16 62 17 1 0 66 0 5 / is $i1 / is $i2 / 0 0 0 0 / is $i3 / 247
11 1 0 42 0 5 0 0 0 0 0 0 1b f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 20
f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 2e f7 f0 43 10 3e 11 1 0 42 0
5 0 0 0 0 0 0 45 f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 57 f7 f0 43 10
3e 11 1 0 42 0 5 0 0 0 0 0 0 6e f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0
0 85 f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 98 f7 f0 43 10 3e 11 1 0
42 0 5 0 0 0 0 0 0 aa f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 cf f7 f0
43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 e1 f7 f0 43 10 3e 11 1 0 42 0 5 0 0
0 0 0 0 eb f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 f8 f7 f0 43 10 3e 11
1 0 42 0 5 0 0 0 0 0 0 10b f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 114
f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 122 f7 f0 43 10 3e 11 1 0 42 0
5 0 0 0 0 0 0 12b f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 13d f7 f0 43
10 3e 11 1 0 42 0 5 0 0 0 0 0 0 14b f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0
0 0 0 155 f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 159 f7 f0 43 10 3e 11
1 0 42 0 5 0 0 0 0 0 0 162 f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 167
f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 16c f7 f0 43 10 3e 11 1 0 42 0
5 0 0 0 0 0 0 170 f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0 0 0 0 175 f7 f0 43
10 3e 11 1 0 42 0 5 0 0 0 0 0 0 179 f7 f0 43 10 3e 11 1 0 42 0 5 0 0 0
0 0 0 183 f7
Here is a patch,- which will do the conversion. Note that the 2 int values are displayed as hex (check the inspector) so if you need the hex as an ascii string, you'll need another conversion...
i dont get why you´d need a conversion to symbols, doesnt the
midiout object do this for you?
LONG is LONG, hex is only a different way how to display it...
I got it work.Thanks for your help
"i dont get why you´d need a conversion to symbols, doesnt the
midiout object do this for you?"
just for the record: yes it does ([midiout], NOT [sxformat]). you don´t have to translate to hex in max.
the help file for sxformat uses capture 500 x as its capture object - the x displays the data in hex instead of decimal. The point is that they are the same data, but max expects decimal as this is what most humans expect. The specification of midi means it will always be hex it receives.
The part where it becomes annoying is you cant take an existing sysex command and just paste it into sxformat, it only takes decimal. So you end up converting to decimal which it then outputs again as hex further down the chain - not too bad with standard sysex commands but I have a 256 bit sysex command to translate!
here's a quick fix to what I just mentioned, if instead of F0 (for example) I have the data formatted correctly as 0xF0 it automatically changes it to decimal
UInt to hex symbol
sprintf symout %04X (or x forlowercase)
Symbol to int
jstrigger (parseInt(a[0],16))
for max v.4.x it only works this way:
[sprintf ´00%02X´]
and the other way round, hex to decimal:
[sprintf 0x%s]
hm, or add a leading symbol like done in html world.
problem with midi is that strings are of arbitrary lenght, so bytewise is more appropiate.
wow, what is regexp \\w doing ;)
regexp \\w\\w separates the digits 2 to 2, in this way you can convert the hex in floats (or ints) with a scale obj.