Atlas Robotics
FundamentalsBasic

Bits, bytes, binary and hexadecimal: the native language of microcontrollers

Atlasbot · 20/8/2026 · 10 min read

Bits, bytes, binary and hexadecimal: the native language of microcontrollers
Bit is a binary digit, Byte is 8 bits, hex is the abbreviation binary

Open any microcontroller datasheet and you'll see countless numbers in the form of 0x1F, 0b1010, "8-bit registers", "16-bit addresses" — it's no coincidence that embedded programming is closely tied to the binary and hexadecimal systems: computer hardware operates entirely on 2-level electrical signals (presence/absence of electricity), so everything the computer "understands" ultimately boils down to the numbers 0 and 1. hey.

What are Bits and Bytes?

Bit (binary digit) is the smallest data unit, only receiving 1 of 2 values: 0 or 1 — corresponding to low/high voltage level in the electronic circuit. Byte is a group of 8 bits, the basic unit of data that most microcontrollers process at a time (although many modern MCUs process 32-bits — 4 bytes — at a time per command).

With 8 bits, a byte can represent 2⁸ = 256 different values (from 0 to 255 without signs) — this is why the uint8_t data type in C can only hold a maximum of 255, and why 8-bit PWM on Arduino only has 256 levels (0-255) and not finer.

Binary system (binary)

The binary system only uses 2 digits (0, 1), unlike the familiar decimal system that uses 10 digits (0-9). Reading the value is identical to a decimal, just with a different base — each place is a power of 2 instead of a power of 10:

Binary: 1 0 1 1
Position: 2³ 2² 2¹ 2⁰ = 8 4 2 1

Value = 1×8 + 0×4 + 1×2 + 1×1 = 11 (decimal)

Why do computers use the binary system?

Digital electronic circuits only need to distinguish two states (power / no power, or high / low voltage) — easier to build, less noisy, and much more stable than having to accurately distinguish 10 different voltage levels as the decimal system would require. This is the fundamental reason why all modern computers are built on binary, not arbitrary choices.

Hexadecimal

Writing long binary numbers (e.g. 10110100) is difficult to read and easy to mistype — the hexadecimal (hex) system, which uses 16 digits (0-9 and A-F), solves this problem. Since 16 = 2⁴, each 1 hex digit corresponds to exactly 4 bits — a byte (8 bits) is always abbreviated to exactly 2 hex digits:

Binary (4 bits)HexBinary (4 bits)Hex
0000010008
0001110019
001021010A
001131011B
010041100C
010151101D
011061110E
011171111F

For example, the binary byte 10110100 is split into 2 groups of 4 bits 1011 and 0100, look up the table to find B and 4 — shortened to 0xB4 (the prefix 0x is the convention that indicates this is a hex number in most programming languages, including C/C++ for microcontroller).

In short: Binary is the real language of hardware; hex is just a short way to write binary for human readability — 1 hex digit is always equal to exactly 4 bits, no complicated conversion required.

Technical details

Formulas

With N bits, the number of available (unsigned) values is 2^N, from 0 to 2^N − 1:

2^N values, range: 0 to (2^N − 1)

For example: N = 8 → 2⁸ = 256 values → 0-255
    N = 16 → 2¹⁶ = 65536 values → 0-65535

Parameters

Sizes and value ranges of common C data types in embedded programming:

Data typeNumber of bitsValue range (unsigned)
uint8_t80 – 255
int8_t8-128 – 127
uint16_t160 – 65.535
uint32_t320 – 4.294.967.295

Register / Bit / Byte

Register GPIOx_IDR (Input Data Register) on the STM32 is a typical example: a 32-bit register but only the lower 16 bits are meaningful (each bit corresponds to a pin from Pin0 to Pin15). Reading the value 0x0005 (binary 0000 0000 0000 0101) immediately indicates that Pin0 and Pin2 are at HIGH level, the remaining pins are LOW — reading 1 time shows the status of 16 pins at the same time, instead of having to read each pin individually.

Practical applications

I2C device addresses are always written in hex form in the datasheet and code (eg: MPU6050 sensor has address 0x68) — comparing this hex address correctly is the first step when debugging the "I2C device not detected" error. Additionally, when a robot has multiple limit switches connected to the same GPIO port, reading the entire register at once (instead of reading each pin with digitalRead() individually) helps get the status of all switches at exactly the same time — avoiding small timing differences between individual reads.

Practical example: reading registers in embedded programming

// STM32 — configure GPIO registers directly in hex
GPIOA->MODER |= 0x00000001;   // set bit 0 = 1, other bits remain the same

// Arduino — set multiple bits at once using OR operation
DDRB |= 0b00000101;   // Set bit 0 and bit 2 of DDRB register to OUTPUT

The microcontroller datasheet describes each register as a string of bits with its own meaning at each position (eg: bit 0 turns on/off feature A, bit 1 turns on/off feature B) — writing hex or binary constants in the code helps compare directly with the bit table in the datasheet, instead of having to manually convert from decimal numbers each time to read.

Common mistakes

  • Confusing 0x10 with decimal 10 — 0x10 in hex is equal to 16 decimal, not 10. Always pay attention to the 0x prefix when reading other people's code or datasheets.
  • Overflow when the data type does not have enough bits — uint8_t x = 255; x = x + 1; gives the result 0 (not 256), because 8 bits can only hold a maximum of 255, plus 1 will "cycle" to 0 — a classic error that causes confusing behavior if bit limits are not understood.
  • Forgetting that bit shifting depends on whether the data type is signed or not — right shift (>>) on signed numbers can leave the sign bit intact (arithmetic shift), different behavior with unsigned numbers — easily causes logic errors that are difficult to detect when manipulating bits directly on the register.
  • Writing the wrong number of bits when manipulating 16/32-bit registers — the register on the STM32 is usually 32-bit, but if you only remember the 8-bit sample from the Arduino, you may miscalculate the bit position to set.

Conclusion

Bits, bytes, binary, and hex are not far-fetched academic knowledge — this is a direct language for reading datasheets, configuring registers, and understanding why data types (uint8_t, uint16_t...) limit values ​​as they do. The next article in this section is about voltage, current, and power — the physical foundation for understanding why electronic circuits work.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

Bits, bytes, binary and hexadecimal: the native language of microcontrollers — Atlas Robotics