Skip to content

Instantly share code, notes, and snippets.

@emdeesee
Last active April 25, 2017 21:12
Show Gist options
  • Select an option

  • Save emdeesee/5c9575b0c8710896698840b1aa780c69 to your computer and use it in GitHub Desktop.

Select an option

Save emdeesee/5c9575b0c8710896698840b1aa780c69 to your computer and use it in GitHub Desktop.
Encode and decode "binary" strings with Common Lisp
(require :split-sequence)
(use-package :split-sequence)
(defun bits->text (s)
"\"01100110 01101111 01101111\" -> \"foo\""
(coerce
(mapcar (lambda (x) (code-char (parse-integer x :radix 2)))
(split-sequence #\space s))
'string))
(defun text->bits (s)
"\"foo\" -> \"01100110 01101111 01101111\""
(format nil "~{~8,'0b~^ ~}"
(mapcar #'char-code (coerce s 'list))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment