Shameless plug: my `bc` [1] can also display bits like this, as well as do bit operations.
It automatically detects how many bits your number must have and uses the minimum, or you can tell it the standard bit sizes or even use a custom bit size. It will handle 2's complement signed integers.
See the manual ([2]), especially the extended math library section ([3]).
It's also a normal `bc`, with every feature of all other implementations.
For old school fans, the HP-16C [1] calculator provided these kinds of functions in a handheld calculator, in 1982. This was the only "programmer" calculator that HP has ever made.
There is a simulator (for Windows) available [2]. (No affiliation; but I made a simulator for the cousin calculator HP-15C [3]).
There's also JRPN [1], not sure how closely it follows the original HP-16C as I've never used the original but it seems to give significant thought to it. It's written in flutter so available on linux and android.
One day I’ll buy a real 16C. But they’re just a little too expensive to easily justify buying. I know there are remakes but there’s just something about the real thing.
I use qalc/qalculate, it has gui/cli version. I got pissed dealing with bc usability problems ("yes I pressed ctrl+c, you know I want to quit, why you ask me to type some command for it?").
> 10+0xff+0b00010 ->hex
10 + 255 + 2 = 0x10B
Also does some fancy unit conversion stuff like "how long it would take to transfer X gigabytes over Y Mbit link
> 200GB / (100Mbit/s)
(200 gigabytes) / ((100 megabits) / second) = 4 h + 26 min + 40 s
bc predates the usage of Ctrl+C for copy pasting in some graphical UIs (not even all of them) by at least one decade. And it's not the sort of command line tool that you'd reasonably expect a clueless novice to stumble upon. And even if they did, bc terminates gracefully and leaves all your inputs on the screen, so there's not much lost if you do accidentally terminate it mid-work.
So there's no really good reason for that behaviour… which is probably why not all bc flavours do it. GNU bc as shipped by Arch e.g. does just silently quit on ^C, and far as I can tell they're not patching it either.
I like the idea and hope you grow it into something of a pen-knife for
numbers. Being able to change the bit width and base on the fly looks
neat. I tend to pull up a Python shell for lots of tasks. Often what I
want is a dumper (like od, hexdump or tcpdump) with the ability to
filter steams with masks and whatnot, like wireshark, and display the
results in various "views" (hex, binary etc as you have provided). It
is hard to make any one tool do all that - but also hard to find
nicely pipeable little tools to work in a Unix way. It might be good
to consider the contexts people will use your tool wrt
stdio/sockets/fifos.
For Linux GUI users I also like the Gnome calculator in programmer mode, which displays the different bases all at once and has options for 2's complement and the like.
Yeah I use that almost daily. Because my company only lets us use windows (and VMs) sometimes I accidentally launch the windows calculator and I’ve discovered it too has a passable programmer mode.
Honestly I missed Calculator.app along with Mail.app on Linux quite a lot!
I settled with Qalculate - it can do some things as Spotlight (currency conversion) and also quite nice for programmer-related tasks. Although I miss few features here and there it is quite good.
i had a casio (i think) calculator with a fold-out keyboard with all the hex digits (A-F) and the boolean operators. it would take input in binary, and hex, but not octal. my then gf bought it me as a bday present. appreciated, but not much used as at the time i could do all the binary/hex/decimal conversions in my head, not to mention converting them into z80 opcodes.
That's very neat. I wouldn't use it even if I had such a need - Emacs Calc seems to do everything this does and much more - but I'm glad people create such nice tools.
Offtopic, but I remember implementing a calculator was Compilers & Parsing 101.
I mention this because the Readme specifically calls out the various ways of inputting an expression, which is a non-issue with any compiler background. (It's handled by the lexer, which is step that handles processing input into "lexical" elements, which are then passed to actual "parser" that constructs the syntactic structure)
Interesting tool! In Rizin[1][2] we have a "visual bits" mode, see "Vb1" command. Moreover, there's "rz-ax" command, supporting various number systems and bits, see "rz-ax -h" help.
Many calculators will do this. I like the CalcTastic Pro for android. This has a programmer mode, which will do all these and more. Its scientific mode will operate with complex numbers as well as real numbers. It can even take the complex factorial.
The tools seems to have been developed because switching between terminal and clunky web-based tools was not fast enough ("did not allow for "nice multitasking""), not sure if switching between terminal on computer and a calculator on the phone would make things better, seems like it'd just add more friction, not less.
It automatically detects how many bits your number must have and uses the minimum, or you can tell it the standard bit sizes or even use a custom bit size. It will handle 2's complement signed integers.
See the manual ([2]), especially the extended math library section ([3]).
It's also a normal `bc`, with every feature of all other implementations.
I should add floating point support, though.
[1]: https://git.yzena.com/gavin/bc
[2]: https://git.yzena.com/gavin/bc/src/branch/master/manuals/bc/...
[3]: https://git.yzena.com/gavin/bc/src/branch/master/manuals/bc/...