From: "Stephen J. Turnbull" <stephen@xemacs.org>
To: Stephen Leake <stephen_leake@stephe-leake.org>
Cc: emacs-devel@gnu.org
Subject: Re: C-x C-e on numbers
Date: Fri, 05 Dec 2014 15:53:36 +0900 [thread overview]
Message-ID: <877fy6lh8v.fsf@uwakimon.sk.tsukuba.ac.jp> (raw)
In-Reply-To: <85oarjnyzx.fsf@stephe-leake.org>
Stephen Leake writes:
> M-: (show-binary 42)
(defun show-binary (n)
"Documentation left as exercise for the reader."
;; hexadecimal version also an exercise
(let ((s (format "%o" n)))
;; loop unrolled for creativity conservation
(setq s (replace-in-string s "0" "000"))
(setq s (replace-in-string s "1" "001"))
(setq s (replace-in-string s "2" "010"))
(setq s (replace-in-string s "3" "011"))
(setq s (replace-in-string s "4" "100"))
(setq s (replace-in-string s "5" "101"))
(setq s (replace-in-string s "6" "110"))
(setq s (replace-in-string s "7" "111"))
;; stripping leading zeros or padding to wordsize, more homework
(concat "#b" s)))
Seriously, does this function really need to be particularly efficient?
next prev parent reply other threads:[~2014-12-05 6:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-04 15:56 C-x C-e on numbers Alfred M. Szmidt
2014-12-04 16:27 ` Andreas Schwab
2014-12-04 16:47 ` Stephen Leake
2014-12-05 6:53 ` Stephen J. Turnbull [this message]
2014-12-05 7:04 ` Stefan Reichör
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877fy6lh8v.fsf@uwakimon.sk.tsukuba.ac.jp \
--to=stephen@xemacs.org \
--cc=emacs-devel@gnu.org \
--cc=stephen_leake@stephe-leake.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).