Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationto_binary

Official ZPE/YASS documentationto_binary

to_binary (mixed value) ⇒ mixed

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

First available: Version

Prior to ZPE 1.8.7

Prior to version 1.8.7 (Portman), this function only accepted a number and converted that number to a binary string.

ZPE 1.8.7 changed the way the function works. Instead of simply accepting a number value, the function can now accept a string. It will convert the characters in the string to it's ASCII numeric values then convert those values to a number. It then returns a list of all those 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.

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()
end function

With version 1.8.7 onwards, this can be simply done with:

function main()
  print(list_combine(to_binary($args[0])), " ")
end function
Feedback 👍
Comments are sent via email to me.