Register Bitfield Decoder

Paste a register value and a field layout to get a decoded table — with presets for common STM32 and AVR registers.

Example: 0x00010023 decodes to CEN=1, DIR=0, CMS=1, ARPE=0, CKD=0, UIF=1.

Check it against real silicon

Chiprun runs your firmware on an emulated microcontroller and hands back the UART output, so you can confirm these numbers rather than trusting them.

Chiprun docs

Formula

field = (register >> low) & ((1 << (high − low + 1)) − 1)

Worked example

0x00010023 decodes to CEN=1, DIR=0, CMS=1, ARPE=0, CKD=0, UIF=1.

  1. CEN = (reg >> 0) & 0x1

    (0x00010023 >> 0) & 0x1

    1

  2. DIR = (reg >> 4) & 0x1

    (0x00010023 >> 4) & 0x1

    0

  3. CMS = (reg >> 5) & 0x3

    (0x00010023 >> 5) & 0x3

    1

  4. ARPE = (reg >> 7) & 0x1

    (0x00010023 >> 7) & 0x1

    0

Frequently asked questions

How do I extract a bitfield from a register?

Shift right by the field's low bit, then mask off the width: `(reg >> low) & ((1 << width) - 1)`. Doing the shift first avoids needing a mask positioned at the field's location.

Why do reserved bits matter?

Because most reference manuals require them to keep their reset value, and future silicon may give them meaning. Assigning a whole register clears them; read-modify-write preserves them. Peripherals that behave oddly after a config change are often a symptom of this.

Why does reading a register not return what I wrote?

Several reasons. Write-only bits read as zero. Clear-on-read flags change state when you look at them. Some fields are shadowed and only take effect on an update event. And some are only writable while the peripheral is disabled — the write silently does nothing otherwise.

Related tools