Skip to content

Instantly share code, notes, and snippets.

@mooz
Created October 6, 2014 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooz/a5015f8a4570bfc30e71 to your computer and use it in GitHub Desktop.
Save mooz/a5015f8a4570bfc30e71 to your computer and use it in GitHub Desktop.
Display `size-byte' in various units
(defun my:byte-to-various-units (size-byte)
"Display `size-byte' in various units."
(interactive "nBytes: ")
(let ((size size-byte)
(size-kib size-byte))
(with-output-to-temp-buffer "*unit*"
(princ (format "%d B\n-----------\n" size-byte))
(dolist (unit '("K" "M" "G" "T" "P"))
(setq size (/ size 1000.0))
(setq size-kib (/ size-kib 1024.0))
(princ (format (concat "%g %siB"
"\t\t"
"%g %sB"
"\n")
size-kib unit
size unit))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment