;;; -*- 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 number-to-bitstring (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 #'number-to-bitstring) ;; (dec2bits ?a) ; 1100001 (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 (number-to-bitstring c) bits) ))) ;; (str-to-bits "What's up Emacs community?") ; 111111 1110000 1110101 [...] (provide 'str-to-bits)