Last active
April 25, 2017 21:12
-
-
Save emdeesee/5c9575b0c8710896698840b1aa780c69 to your computer and use it in GitHub Desktop.
Encode and decode "binary" strings with Common Lisp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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