Skip to content

Commit 5280a76

Browse files
committed
Add hex utility for writing hex literals in notes.
1 parent ff83de2 commit 5280a76

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

www/notes/utils.rkt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@
3636
(define (save-file f s)
3737
(with-output-to-file f (λ () (display s)) #:exists 'replace))
3838

39-
(define (binary i [len 0])
39+
(define (base i b [len 0])
4040
(typeset-code #:block? #f #:indent 0
41-
(string-append "#b"
42-
(~a (number->string i 2)
41+
(string-append "#"
42+
(case b [(2) "b"] [(16) "x"])
43+
(~a (string-upcase (number->string i b))
4344
#:left-pad-string "0"
4445
#:align 'right
4546
#:min-width len))))
4647

48+
(define (hex i [len 0])
49+
(base i 16 len))
50+
(define (binary i [len 0])
51+
(base i 2 len))
52+
4753
(define (src-code lang)
4854
(margin-note (small-save-icon) " "
4955
(link (string-append "code/" (string-downcase lang) ".zip") "Source code")

0 commit comments

Comments
 (0)