String to binary

/ Published in: Python
Save to your folder(s)

Copy this code and paste it in your HTML
  1. binary_int = lambda i, c = (lambda i, c: i and (c(i >> 1, c) + str(i & 1)) or ''): c(i, c)
  2. binary_str = lambda s: ''.join([binary(ord(ch)) for ch in s])
  4. print binary_str('hello world')

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.