tl;dr: a CLI-based and Alfred-based programmer’s calculator
is now available on GitHub and via
cargo install radix-calc
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:
- It should always be near at hand, even when working on a remote ssh/telnet/serial connection.
- It understands decimal and hexadecimal (and ideally octal+binary as well) input and output.
- It interacts conveniently with my clipboard.
- (bonus points) It performs speaks infix notation, not postfix/RPN.
So to solve this problem I built a new CLI tool (
understands typical infix expressions for integer programming arithmetic. On
top of that I layered an Alfred workflow that effectively replaces the builtin
rc 5+5 instead of
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 install radix-calc will do the trick.
Here’s a short demo of the CLI: