⚡
usefultools.dev
0b

Bit Register Calculator – Bits, Fields & C Masks

NOVO

Bit register calculator for 8, 16 and 32-bit MCU registers: click bits, see hex, decimal, binary and octal, name bit fields and copy the C set/clear/mask code. Free.

Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.

Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.

Signed (two's complement): -91 · bits set: 4

Single bit helper
bit 3 = 0 · mask 0x08
REG |= (1u << 3);     /* set */
REG &= ~(1u << 3);    /* clear */
REG ^= (1u << 3);     /* toggle */
if (REG & (1u << 3)) { /* bit 3 is set */ }
Named bit fields
FieldBitsValueHex
EN00x1
MODE2:10x2
IRQ30x0
PRESC7:40xA

C for each field (CMSIS-style _Pos / _Msk macros, writing the current value):

#define EN_Pos  0
#define EN_Msk  (0x1u << EN_Pos)  /* 0x01u */
en = (REG & EN_Msk) >> EN_Pos;
REG = (REG & ~EN_Msk) | ((1u << EN_Pos) & EN_Msk);

#define MODE_Pos  1
#define MODE_Msk  (0x3u << MODE_Pos)  /* 0x06u */
mode = (REG & MODE_Msk) >> MODE_Pos;
REG = (REG & ~MODE_Msk) | ((2u << MODE_Pos) & MODE_Msk);

#define IRQ_Pos  3
#define IRQ_Msk  (0x1u << IRQ_Pos)  /* 0x08u */
irq = (REG & IRQ_Msk) >> IRQ_Pos;
REG = (REG & ~IRQ_Msk) | ((0u << IRQ_Pos) & IRQ_Msk);

#define PRESC_Pos  4
#define PRESC_Msk  (0xFu << PRESC_Pos)  /* 0xF0u */
presc = (REG & PRESC_Msk) >> PRESC_Pos;
REG = (REG & ~PRESC_Msk) | ((10u << PRESC_Pos) & PRESC_Msk);

Bits 15 and above use 1UL because int is only 16 bits on AVR. Need plain XOR/AND on long hex strings? Try the Bitwise Calculator; for any base conversion use the Number Base Changer.

⚡

Exemplos rápidos

Entradas típicas e os resultados que esta ferramenta gera.

Bases
0xA5 (8-bit)
1010 0101 = 165 = -91 signed
Field
Field MODE:2-1 of 0xA5
2
C
Set bit 5
REG |= (1u << 5);
32-bit
Set bit 20
REG |= (1UL << 20);
Hex
Set bit 31 (32-bit)
0x80000000
📖

Visão geral

Configuring a timer, UART or GPIO port usually means writing a register value built from several bits and multi-bit fields. This bit register calculator shows an 8, 16 or 32-bit register as a grid of clickable bits, keeps hexadecimal, decimal, binary and octal views in sync, and shows the signed value too.

Describe the register layout once, for example EN:0, MODE:2-1 and PRESC:7-4, and each field is coloured on the grid with its current value, which you can edit directly. The tool then writes the matching C: set, clear, toggle and test expressions for a bit, plus CMSIS-style _Pos and _Msk macros with read and write statements for every field.

It is aimed at embedded developers working from a datasheet register table. Everything runs in your browser.

Por que usar esta ferramenta?

  • Click bits instead of converting by hand
  • Hex, decimal, binary and octal stay in sync
  • Named fields with editable values
  • Copy-ready C masks and macros
  • Free and runs entirely in your browser
⭐

Recursos

🖱️

Clickable bit grid

Toggle any bit; rows are grouped per byte with bit numbers, so it fits on a phone.

🔢

Four bases

Type in hex, decimal, binary or octal and the other views update; underscores and 0x prefixes are accepted.

🏷️

Named bit fields

Define fields as NAME:bit or NAME:hi-lo, see them coloured on the grid, and edit their values.

↔️

Shift and mask helpers

Set, clear or toggle bit n, shift left or right, invert, set all and clear all.

💻

C code

reg |= (1u << n) style expressions plus _Pos/_Msk defines and field read/write statements.

⚠️

AVR-safe literals

Uses 1UL for bit 15 and above, because int is only 16 bits on 8-bit AVR.

🛠️

Como usar

1

Set the width

Choose 8, 16 or 32-bit and type the register name used in your code.

2

Enter or click

Type a value in any base or click bits on the grid to build it.

3

Name the fields

List the fields from the datasheet in Named bit fields, then read or edit their values in the table.

4

Copy the C

Copy the single-bit snippets or the field macros straight into your firmware.

🤔

Perguntas frequentes