Bit-parser – decode and encode compact bitfields into human-readable structures

1 pointsposted 8 hours ago
by developer4ltu

1 Comments

developer4ltu

8 hours ago

Hi HN,

I built a small Python helper called bit-parser for decoding and encoding compact bitfields (status bytes, flags, small counters) into human-readable structures — and back again.

It’s aimed at embedded / IoT / protocol-heavy systems where devices emit short hex strings, but humans need to reason about individual bits, ranges, and meanings.

Repo: https://github.com/vitalij555/bit-parser

The problem

In many protocols, a single byte (or two) encodes multiple independent signals:

boolean flags

RFU / reserved bits

small counters

mode selectors

multi-bit values with constrained ranges

Typical solutions end up as:

scattered masks and shifts

duplicated logic across CLI tools, tests, and UIs

decode-only helpers with no clean reverse operation

frontend teams re-implementing the bit layout by hand

I wanted something small and declarative, where:

the bit layout is defined once

decoding and encoding are symmetric

the same definition can drive CLIs, validation, and UI calculators