BitBench Helps Parse Binary Data

Maybe its a capture file from a network dump. Maybe it’s from an Arduino. Maybe it is a random file off the Internet. But there will be a time when you have a file full of seemingly meaningless numbers and you need to impose order. We usually resort to a printout and highlighter, but BitBench seems like a better option. That link will take you to the code, but if you want to play with a live instance, the author has one loaded with example data.

If you look at the live example, there’s an area up top with a lot of raw hex data. The area below that shows a format string. By default that’s:

hh ID:hh b CH3d TEMP_C:12d HUM:d CRC:8h | 8h 16h 16h

From the page, here’s the description of the format:

Use “h” for hex (default 4 bits), “b” for binary (default 1 bit), “d” for decimal (default 8 bits).
Use optional bit length prefix numbers. Use “~” to invert bits, use “^” to reverse LSB/MSB. Other characters are output as-is.

So in the example string, hh is an 8-bit hex number. ID: is just a label, followed by another 8-bit number.  Then the bottom displays the data formatted as you wish and gives you a way to pad the fields with extra bits and see the results. You can also invert or shift all the bits.

This is actually handy and the author mentions it is the result of one day of prototyping. It would be nice if you could write simple math expressions, handle BCD, and maybe even have multiple formats based on some conditions. But maybe that’s version two.

This reminded us of the web-based hex editor we saw a while back. Of course, if your hex data is machine code, you could try an online disassembler.

16 thoughts on “BitBench Helps Parse Binary Data

    1. What about XS-3 coded number then? ;-) It’s like BCD but easier to complement for limited hardware. I’m currently designing/building a calculator using only transistors like the ones in the late 60’s and I use XS-3 just for the heck of it – not just to save some transistors in the implementation, I’m up to over 3000 by now. :-)

    2. Well, yeah. I meant like interpret ASCII BCD — you are talking packed BCD… so 0x393135 = 915. Then there’s dense pack (watch for that in an upcoming post), but that is barely BCD.

  1. Reminds me of a util that was popular among down and dirty hacker overclockers in the noughties for editing binary chipset data…. c’mon brain, work, gimme name of a random util last seen 15 years ago, or I shall poke you with a Q-tip.

  2. It would be nice if there was a way to escape the format characters as literals. For instance, if I want my hex numbers to have an 0x prefix, it won’t let me do it because a number and an x are always interpreted as format characters

  3. Thanks for all the interesting links to similar tools. Maybe a bit of context is needed: The main application here is to reverse engineer short SDR data packets. E.g. rtl_433 will grab a transmission, analyze the modulation and dump the bits as hex. Now you just paste that in and fiddle with the format until you get an idea what’s in the data. Or you paste the link to your work-in-progress to ask for ideas or showcase your findings.
    (also I really got bored telling people that rtl_433 won’t add binary formatted output for the hex-impaired.)

    re BCD: Use “c” to show 0x313935 as “1 9 5” or use “h” to show 0x195 (BCD — a nibble per digit) as “1 9 5”.

Leave a Reply to [matseng]Cancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.