Skip to content

Instantly share code, notes, and snippets.

@miyamuko
Created July 8, 2010 00:02
Show Gist options
  • Save miyamuko/467462 to your computer and use it in GitHub Desktop.
Save miyamuko/467462 to your computer and use it in GitHub Desktop.
;; フォロワーからの「いっその事 0 か 1 のみで話せばいいのに」
;; という返信には「無理。。」と答えている。
;; http://www.itmedia.co.jp/news/articles/1007/07/news065.html
;; http://twitter.com/yoichiw/status/17930186153
(defun binary->string (bin-str)
(format nil "~{~A~}"
(mapcar #'(lambda (bin)
(code-char (parse-integer bin :radix 2)))
(split-string bin-str #\SPC))))
(defun string->binary (str)
(format nil "~{~8,'0B~^ ~}" (map 'list #'char-code str)))
(string->binary "@yoichiw Hello!")
;;=> "01000000 01111001 01101111 01101001 01100011 01101000 01101001 01110111 00100000 01001000 01100101 01101100 01101100 01101111 00100001"
(length (string->binary "@yoichiw Hello!"))
;;=> 134
(binary->string (string->binary "@yoichiw Hello!"))
;;=> "@yoichiw Hello!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment