Last active
August 7, 2018 03:59
-
-
Save cvalarida/1a808488708766d7e7bce524de0651ad to your computer and use it in GitHub Desktop.
An Elisp attempt at a little engineering problem--converting a decimal number to binary.
This file contains 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
(defun dec-to-bin (dec) | |
(interactive "nDecimal number to convert: ") | |
(setq debug-on-error t) | |
(let ((bin-string "") | |
(current-dec dec)) | |
(while (/= 0 current-dec) | |
(setq bin-string (concat (number-to-string (% current-dec 2)) bin-string)) | |
(setq current-dec (truncate (/ current-dec 2)))) | |
(message "%d in binary is %s" dec bin-string))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment