helper: convert hex to octal or dezimal
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -11,3 +11,29 @@
|
||||
(cl-map 'vector
|
||||
(lambda (c) (make-glyph-code c 'escape-glyph))
|
||||
(format "\\%02x" x)))))
|
||||
|
||||
|
||||
(defun use-octal-not-hex ()
|
||||
"Use cctadecimal escape sequences instead of hex."
|
||||
(interactive)
|
||||
(require 'cl-lib)
|
||||
(unless buffer-display-table
|
||||
(setq buffer-display-table (make-display-table)))
|
||||
(setq unprintable (append (number-sequence 127 255) (number-sequence 0 8) (number-sequence 11 31)))
|
||||
(cl-loop
|
||||
for x in unprintable
|
||||
do (aset buffer-display-table (unibyte-char-to-multibyte x)
|
||||
(cl-map 'vector
|
||||
(lambda (c) (make-glyph-code c 'escape-glyph))
|
||||
(format "\\%0do" x)))))
|
||||
|
||||
;; Hex string to dezimal
|
||||
(string-to-number "FF" 16) ;; => 255
|
||||
|
||||
;; Hex string to dezimal
|
||||
(string-to-number "377" 8) ;; => 255
|
||||
|
||||
;; Dezimal string to hex
|
||||
(format "%X" 255) ;; => "FF"
|
||||
|
||||
(string-to-number "e001" 16)
|
||||
|
||||
Reference in New Issue
Block a user