reddit / emacs

Convert numbers in different bases with the Emacs package Calc

tonyaldon · 2022-11-09 18:17
MstchCmBck · 2022-11-09 19:44
I use REPL with Python or Elisp interpreter for that purpose. I don't know if it's something built in Emacs.
tonyaldon · 2022-11-09 21:28
I used to use elisp too.
funkiestj · 2022-11-09 21:34
calc is amazing. It does a ton of stuff but I mostly use it for * big integers * converting between bases and grouping hex digits (comma every 4 digits with 'd G' keybind) * units conversion (e.g. how long does it take light to move through 1M of optical fiber?) * plugging numbers into a formula, editing a formula * grabbing a column (or matrix) of numbers and then doing a vector reduce the info file docs for calc are very good too
tonyaldon · 2022-11-09 21:45
Really amazing.
7890yuiop · 2022-11-09 21:47
Calc is excellent, but you don't necessarily need to use it for base conversions, as the elisp integer syntax already reads numbers in bases 2 to 36: The syntax for integers in bases other than 10 consists of ‘#’ followed by a radix indication followed by one or more digits. The radix indications are ‘b’ for binary, ‘o’ for octal, ‘x’ for hex, and ‘RADIXr’ for radix RADIX. Thus, ‘#bINTEGER’ reads INTEGER in binary, and ‘#RADIXrINTEGER’ reads INTEGER in radix RADIX. Allowed values of RADIX run from 2 to 36, and allowed digits are the first RADIX characters taken from ‘0’–‘9’, ‘A’–‘Z’. Letter case is ignored and there is no initial sign or final period. For example: #b101100 ⇒ 44 #o54 ⇒ 44 #x2c ⇒ 44 #24r1k ⇒ 44 You get output for decimal, octal, and hexadecimal (and char) by default (generated via `format`) if you `eval-expression` any integer. `M-: #24r1k` => `44 (#o54, #x2c, ?,)` You may need calc if you need to convert *to* a base other than those three, however. Also note that with Emacs gaining bignum support in 27.1, the above is nowadays equally fine for very large integers.
thevoidzero · 2022-11-09 22:21
I've been searching for someone who is familiar with unit conversion in calc. How good is it? I've recently written an interface to gnu units for units based calculations and conversion but don't have comparison with calc. It's in melpa with the name "units-mode", The source is in github.
funkiestj · 2022-11-09 23:17
you can read the calc docs: [basic operation on units](https://www.gnu.org/software/emacs/manual/html_mono/calc.html#Units). Strangely enough, my emacs distribution has the calc package but no info files installed. the URL above has the same info that is suppose to be in emacs *info*.
funkiestj · 2022-11-09 23:24
try M-x calc # enter calc 'c # ' - algebraic mode, c - speed of light ub # convert 'c' to base units which are m/s
jazzpecq · 2022-11-10 00:36
This works also for fractional numbers, so you can enjoy Pi in base 7, for example.
Bodertz · 2022-11-10 02:22
If it's Debian, they have a disagreement with the FSF as to what constitutes a free documentation license, so by default they don't include documentation under what they consider to be a non-free documentation license.
7890yuiop · 2022-11-10 05:07
See also https://www.emacswiki.org/emacs/EmacsForDebian E.g. In a system with `emacs25` you would also need to install the 'optional' packages `emacs25-el` and `emacs25-common-non-dfsg` in order to avoid a broken (IMO) installation of Emacs. n.b. I grabbed the above names from a package search on an Ubuntu 18.04 machine. The naming might differ for newer versions, and I believe the "kellyk" PPA packages *might* incorporate the documentation by default (based only on anecdotal evidence).
tonyaldon · 2022-11-10 07:38
I didn't know about. Thanks u/7890yuiop.