Bit-Field / Register Designer — Pack & Decode Named Bit Fields
Lay out named bit-fields inside an 8, 16, 32 or 64-bit register word — like documenting a hardware control register — then pack the field values into the full word (hex + binary, with a coloured bit-map), or decode a hex word back into each field. Warns on overlapping fields and values too big for their width. Runs entirely in your browser with BigInt.
How to Use
- Pick a register width (8, 16, 32 or 64 bits).
- Add a row for each field — give it a name, its high and low bit positions (MSB:LSB), and a value. The width column is filled in for you.
- Read the packed word at the top in hex and binary, with every field coloured in the bit-map strip below it.
- To go the other way, type a hex (or 0b / decimal) word into the Decode box and press Decode — each field’s value is filled from the matching bits.
- Watch for warnings: a red row means the value does not fit its width, and overlapping bit ranges are flagged on the bit-map.
| Field name | High bit | Low bit | Width | Value |
|---|
Design a register, one named field at a time
Hardware control registers, packet headers and packed status words all squeeze several small numbers into one integer by giving each a fixed range of bits. This designer lets you lay that out the way a datasheet does: pick a register width of 8, 16, 32 or 64 bits, then add a row for each field with a name, a high and low bit position, and a value. The tool immediately packs every field into the full word and shows it in hex and binary, with each field coloured in a bit-map strip so the layout is obvious at a glance. Go the other way by typing a word into the Decode box: each field’s value is pulled straight out of the matching bits. Everything is computed locally with JavaScript BigInt, so a full 64-bit word is exact and nothing about your design leaves the browser.
How packing and decoding work
A field occupying bits [high:low] has a width of high − low + 1 and a mask of (1 << width) − 1, which is just that many 1-bits. To pack, each field’s value is first reduced to its own bits with value & mask, shifted up into position with << low, and all the fields are combined with bitwise OR: word = Σ (valueᵢ & maskᵢ) << lowᵢ. To decode, the reverse extracts each field with (word >> low) & mask. Two problems are flagged live: a value that needs more bits than its width (its high bits would spill into a neighbour, so they are masked off and the row turns red) and two fields that overlap the same bit, which would corrupt both on pack. Bit 0 is the least-significant bit on the right; the strip is drawn most-significant-bit first to match register documentation.
Quick reference
About the Bit-Field / Register Designer — Pack & Decode Named Bit Fields
The Bit-Field / Register Designer — Pack & Decode Named Bit Fields is a free tool for everyday tasks. It runs right in your web browser, so there is nothing to download. Lay out named bit-fields inside an 8, 16, 32 or 64-bit register word — like documenting a hardware control register — then pack the field values into the full word (hex + binary, with a coloured bit-map), or decode a hex word back into each field. Warns on overlapping fields and values too big for their width. Runs entirely in your browser with BigInt.
How it works
Type your numbers into the boxes. The answer shows up right away — you do not have to press a button. If you change a number, the answer changes too. So you can try different numbers and watch what happens, or check an answer you worked out yourself. Just make sure each box has the right kind of number in it.
Want the deeper story? The Knowledge Base explains the ideas behind the tools in more detail.
Frequently Asked Questions
How are the fields packed into the word?
Each field contributes <code>(value & mask) << low</code>, where <code>mask = (1 << width) − 1</code> keeps only the field’s own bits, <code>low</code> is its least-significant bit position, and <code>width = high − low + 1</code>. All the shifted fields are then OR-ed together. For example a 4-bit field A at bits [3:0] holding 0xF and a 4-bit field B at [7:4] holding 0x1 pack to <code>0x1 << 4 | 0xF = 0x1F</code>.
How does decoding work?
Decoding is the reverse: for each field the tool computes <code>(word >> low) & mask</code> to extract just that field’s bits as a value. Type a word in the Decode box (hex with 0x, binary with 0b, or plain decimal) and every field’s Value column is refilled from it.
Which bit is bit 0, and which way does the bit-map read?
Bit 0 is the least-significant bit (worth 1) and sits on the right; the most-significant bit (width − 1) is on the left. The bit-map strip is drawn MSB-first to match how registers are usually documented in a datasheet, with bit indices labelled above.
What do the warnings mean?
Two checks run live. A value too big for its width (for instance 0x1F in a 4-bit field, which needs 5 bits) is highlighted in red and the excess bits are masked off before packing. Overlapping fields — two ranges that claim the same bit — are flagged because the packed result would mix them; reposition one field to clear it.
Is 64-bit accurate, and is anything uploaded?
Yes and no respectively. All arithmetic uses JavaScript <code>BigInt</code>, so a full 64-bit register is exact with no floating-point rounding, and the entire tool runs locally in your browser — nothing about your register layout is sent to a server.
How do I use the Bit-Field / Register Designer — Pack & Decode Named Bit Fields?
Simply type your numbers and read the result, which refreshes the instant you change something. There is nothing to submit and nothing to wait for.
Is it free? Does it work without internet?
Yes to both. It is free with no sign-up, and once the page has loaded it keeps working even with no internet.
Where does my data go?
Nowhere — every calculation runs on your own device. Nothing you enter is uploaded, logged, or stored.
Common Use Cases
Documenting hardware registers
Recreate a datasheet control/status register: name each field, give it a bit range, and read off the hex value for any combination of settings.
Firmware & driver development
Work out the exact word to write to a peripheral register, or decode a value you read back to see which fields are set.
Protocol & packet headers
Lay out a fixed-width header (version, flags, length) as bit-fields and pack or decode the on-the-wire word.
Learning bit-fields
See exactly how masks, shifts and field positions combine into a single integer, with a coloured bit-map making the layout obvious.
Last updated: