Browse the docs

bin

Reads text as a binary number and returns it as an ordinary number.

Keyboard Maestro: BIN

Details #

bin(text) takes exactly one argument and returns a number. The argument is read as text in base 2 (binary), so bin("1010") is 10.

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. {{ bin(text) }}

Examples #

bin("1010")
→ 10
bin(code)
→ 255
Sample variableValue
code0b11111111

Gotchas #

  • Calling it with no argument or more than one is an error: bin() takes 1 argument, got 2.

  • Text that isn't a binary number stops the step: bin() needs a binary number, got "zz" (showing the first 20 characters it was given).

  • A number argument is turned into text first, so bin(10) reads the digits "10", not the value ten.

  • Only whole numbers are read; a decimal point is an error.