Hacker News new | past | comments | ask | show | jobs | submit login
TUI calculator for programmers working close to the bits (github.com/alt-romes)
127 points by romes on Jan 30, 2023 | hide | past | favorite | 36 comments



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.

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/...


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]).

[1]: https://hpmuseum.org/hp16.htm [2]: http://hp16c.org [3]: https://hp15c.com


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.

[1] https://jrpn.jovial.com/


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 own swissmicro remake. It is excellent

https://www.swissmicros.com/product/dm16l


There’s also Bitwise [0] which has support for IP addresses

[0] https://github.com/mellowcandle/bitwise


I use ipcalc for that, dumps some more useful stuff about net

    -> ᛯ ipcalc 1.1.1.1/23
    Address:   1.1.1.1              00000001.00000001.0000000 1.00000001
    Netmask:   255.255.254.0 = 23   11111111.11111111.1111111 0.00000000
    Wildcard:  0.0.1.255            00000000.00000000.0000000 1.11111111
    =>
    Network:   1.1.0.0/23           00000001.00000001.0000000 0.00000000
    HostMin:   1.1.0.1              00000001.00000001.0000000 0.00000001
    HostMax:   1.1.1.254            00000001.00000001.0000000 1.11111110
    Broadcast: 1.1.1.255            00000001.00000001.0000000 1.11111111
    Hosts/Net: 510


I've been using Bitwise for quite some time now and it is my favorite tool for this


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


Not for you, since qalc seems to fit your use case, but for anyone else that wants `bc` to exit with Ctrl+c.

If you use my `bc` ([1]), configure it with:

    ./configure.sh -O3 -Sbc.sigint_reset
That build will then exit on Ctrl+c.

[1]: https://git.yzena.com/gavin/bc


> yes I pressed ctrl+c, you know I want to quit

Normal people would assume that you wanted to copy something into the clipboard.


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.


Pretty nice looking! Also for anyone on a Mac I find programmer mode (⌘-3) in the built-in Calculator.app pretty useful for this purpose.


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.

https://imgbox.com/SrMD3LoP


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.


Does it not allow WSL?


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.



Looks great! But you may want to consider a different name as PCalc is already a popular calculator app:

https://pcalc.com/


Yup - took me few minutes to figure out why my Portage package pcalc has quite a different TUI. Not the best move to name it like that I'd say.


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.

sadly, no more - too old and forgetful

this would have been about 1984


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.

[1] https://rizin.re

[2] https://github.com/rizinorg/rizin


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.

It can operate on rpn as well as algebraic.

It is good.


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.


[pulls out HP-16C from drawer under the desk]

…I think I'll stay old school and continue pressing those satisfying physical keys.


Anyone know the font in the screenshot?


I think it's Menlo


Any suggestions for similar "close to the bits" but with support for floats?


Well, Julia has a `bitstring` function that understands floats:

  julia> bitstring(Int32(4))
  "00000000000000000000000000000100"

  julia> bitstring(2.2)
  "0100000000000001100110011001100110011001100110011001100110011010"


Nice thought. (Coincidentally, I've recently been using Julia to explore collaborative compilation, spiking numeric literals.)


I rotate between my TI-86, TI-89 and v200.


I need to do one with the lcd replacement hacks for the 89. The contrast in that calculator is crap and readability is really poor.


Nice, but I would prefer an RPN version.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: