hex
Reads text as a hexadecimal number and returns it as an ordinary number.
Keyboard Maestro: HEX
Details #
hex(text) takes exactly one argument and returns a number. The argument is read as text in base 16 (hexadecimal), so hex("ff") is 255.
Spaces around it are ignored, capitals and small letters both work, and a 0x, 0b or 0o prefix is dropped. A leading minus sign is allowed. To go the other way, use formatBase.
Parameters #
Takes 1 argument.
{{ hex(text) }}
Examples #
hex("ff")255hex(code)26| Sample variable | Value |
|---|---|
code | 0x1A |
Gotchas #
Calling it with no argument or more than one is an error:
hex() takes 1 argument, got 2.Text that isn't a hexadecimal number stops the step:
hex() needs a hexadecimal number, got "zz"(showing the first 20 characters it was given).A number argument is turned into text first, so
hex(10)reads the digits "10", not the value ten.A leading
0bor0ois dropped like a prefix, sohex("0b1")reads just1, not0xb1. Write"00b1"to get 0xb1.Only whole numbers are read; a decimal point is an error.