radix-calc: a programmer's calculator for the CLI and Alfred

tl;dr: a CLI-based and Alfred-based programmer’s calculator is now available on GitHub and via cargo install radix-calc

screenshot of the radix-calc Alfred workflow

At work I deal with a lot of hexadecimal and binary arithmetic. Some of it I can do in my head with little effort – most addition is pretty easy, most hex/decimal/binary conversions are easy for small values – but the rest of it is tedious and distracting to convert by hand. There are lots of tools out there to help with these calculations but none of them met my needs:

  1. It should always be near at hand, even when working on a remote ssh/telnet/serial connection.
  2. It understands decimal and hexadecimal (and ideally octal+binary as well) input and output.
  3. It interacts conveniently with my clipboard.
  4. (bonus points) It performs speaks infix notation, not postfix/RPN.

So to solve this problem I built a new CLI tool (radix-calc) that understands typical infix expressions for integer programming arithmetic. On top of that I layered an Alfred workflow that effectively replaces the builtin calculator (e.g, rc 5+5 instead of =5+5).

I wrote the expression parser using Rust and the rust-peg crate. Partly this was for speed and safety, but primarily it was about learning a bit of Rust, which has looked exciting for a while now. It would have been much faster to throw this together in C (because I write it most days of the week) or with a scripting language like Ruby or Python. Working with Rust was a lot of fun and I’m looking forward to future projects using it.

You can get the source from GitHub. If you want to install the Alfred workflow, that can also be downloaded directly from GitHub. If you are only interested in the CLI utility and you already have cargo installed, then cargo install radix-calc will do the trick.

Here’s a short demo of the CLI: