Bit Field Extractor
Extract and label bit fields from register values.
This tool slices a register value into named bit fields: enter the hex value (up to 64-bit), define each field by LSB position and width, and read the decoded values in decimal and hex. The bit strip colors every field's bits so you can check your definitions against the datasheet's register map at a glance.
How it works
Extracting a bit field is two operations: shift the value right by the field's LSB, then mask to its width — (value >> lsb) & ((1 << width) − 1). Datasheets specify fields as [MSB:LSB]; width is MSB − LSB + 1. The tool applies that formula per field with 64-bit-safe arithmetic and renders the value bit by bit, MSB on the left, so mistakes in LSB/width definitions show up visually as bits colored under the wrong field.
Worked example
[7:0] → (v>>0)&0xFF = 0x34
[19:8] → (v>>8)&0xFFF = 0xE12 · [31:20] → 0xCAF
Parameters
| Parameter | Value | Notes |
|---|---|---|
| Extraction | (v >> lsb) & (2ʷ−1) | |
| Field spec | LSB + width | [MSB:LSB] → width = MSB−LSB+1 |
| Value size | up to 64 bit | BigInt-exact |
| Overlaps / gaps | allowed | reserved bits stay uncolored |
C implementation
#include <stdint.h>
/* Extract WIDTH bits starting at LSB from a register value */
#define FIELD(reg, lsb, width) \
(((reg) >> (lsb)) & ((1u << (width)) - 1u))
uint32_t reg = 0xCAFE1234;
uint32_t low = FIELD(reg, 0, 8); /* 0x34 */
uint32_t mid = FIELD(reg, 8, 12); /* 0xE12 */
uint32_t high = FIELD(reg, 20, 12); /* 0xCAF */FAQ
▸How do I read a field defined as bits [15:8] in a datasheet?
That notation means MSB 15 down to LSB 8 — enter LSB 8, width 8 here. The extraction is (value >> 8) & 0xFF: shift the field down to bit 0, then mask its width. The colored strip shows exactly which bits each field claims.
▸Why does the bit strip number bits from the right?
Bit 0 is by convention the least significant bit, on the right in the usual written order — matching how datasheets label register maps. The ruler under the strip marks every 4th bit to make nibble boundaries easy to count.
▸Can fields overlap or leave gaps?
Yes — the tool extracts each field independently, so overlapping definitions are allowed (the strip colors the first-defined owner) and undefined bits simply stay uncolored. That mirrors real register maps, which often have reserved gaps.
▸How large a value can I decode?
Up to 64 bits (16 hex digits). Extraction uses arbitrary-precision integers internally, so 64-bit registers with fields crossing the 32-bit boundary decode exactly.
▸Is my data uploaded?
No. Extraction runs locally in your browser.