Predefined function reference

to_binary

A reference entry for to_binary

Predefined function · numerical_and_arithmetic

to_binary (mixed value) ⇒ mixed

Transforms a real into a binary string, or a string into a list of binary strings.

Example program

The following example converts an arbritray string of text from the command line arguments into a binary string, with each binary character separated by a space.

YASS
function convert_char($ch)
  $bs = to_binary(character_to_integer($ch))
  return $bs
end function

function convert_word($w)

  $output = ""
  $len = string_get_length($w)
  for($i = 0 to $len){
    $ch = convert_char(string_get_character_at($w, $i))
    $output = $output & $ch & " "
  end for

  return $output

end function

function main()
  print(convert_word($args[0]))
end function

Strings can be converted to binary values with:

YASS
function main()
  print(list_combine(to_binary($args[0])), " ")
end function