;;; -*- lexical-binding: t -*- ;; ;; cred: ;; https://codereview.stackexchange.com/q/186840 ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/str-to-bits.el (require 'esh-util) (defun num-to-bits (num) (let ((s "")) (while (> num 0) (setq s (concat (number-to-string (logand num 1)) s)) (setq num (ash num -1)) ) (if (string= "" s) "0" s) )) (defalias 'dec2bits #'num-to-bits) (defalias 'char2bits #'num-to-bits) (defun str-to-bits (str &optional delim) (interactive "sString: ") (or delim (setq delim " ")) (let ((bits)) (dolist (c (string-to-list str) (mapconcat #'eshell-stringify bits delim)) (push (num-to-bits c) bits) ))) ;; (str-to-bits "What's up Emacs community?") ; 111111 1110000 1110101 [...] (provide 'str-to-bits)