So I get that we can convert numbers to hexadecimals using %Hex2%. But what if we want to convert hex to integers? Can anyone help? Dealing with midi packets here.
Perhaps 'decimal' is a better search term than 'integer' ?
(they are all, of course, integers, whether binary, octal, decimal or hex)
I tried that. Can't seem to get the expected result though.
Attached is a screenshot where keyboard maestro is receiving middle C ie note number 60 / hex 3C. Tried converting the tokens but the results are just 0's.
Tried binary, octals, currency, even percentage, can't convert that 3C to 60. My use of syntax are correct in the example right?
How about just executing a script:
Hex to Decimal.kmmacros (2.7 KB)
Got it – those are showing values in various bases, rather than reading them.
For reading a Hex string KMVar to a numeric value, I would personally use JS parseInt(String, 16)
Or, if possible, use the
zero x prefix:
As @ComplexPoint says, you can use 0xAF to interpret numbers as hex.
Further, you can use the CALCULATE function to interpolate non-numeric variables, so for example:
- Set variable HexVar to text “AF”
- Set variable ValueVar to calculation “CALCULATE(0x%Variable%HexVar%)”
I should add a HEX function for this in the future.
Wow! Thanks complexpoint and mrpasini. Both your script suggestions worked really well!
I never had to deal with scripts before within the keyboard maestro environment. So the use of these approaches is a totally new concept to me.
I'll have to dig deeper into scripting. It seems to be a seriously powerful tool for future problem solving.
Thanks for the further suggestion peternlewis. Will try that out further tomorrow. Looks promising