Learn binary, hex and bitwise operations
Each guide answers one question. Each guide has a worked example and a link to the bit editor.
Concepts
How binary, two’s complement, masks and byte order work.
- How binary numbers work
Binary uses two digits, 0 and 1.
- How two’s complement works
Two’s complement stores a negative value in a fixed number of bits.
- Signed and unsigned values
An unsigned value uses all its bits for the magnitude.
- How to use a bit mask
A mask is a value that selects one or more bits.
- How bit shifts work
A left shift moves all bits to a higher position.
- Big endian and little endian
Endianness sets the order of the bytes of a value in memory.
- Why hex suits binary values
One hex digit shows exactly four bits.
Converters
Convert between decimal, hex and binary, with every step.
- Convert decimal to binary
To convert a decimal value into binary, divide the value by 2 and keep the remainder.
- Convert binary to decimal
To convert a binary value into decimal, find each bit that has the value 1.
- Convert decimal to hex
To convert a decimal value into hex, divide the value by 16 and keep the remainder.
- Convert hex to decimal
To convert a hex value into decimal, take each digit and its position.
- Convert binary to hex
To convert a binary value into hex, split the bits into groups of four.
- Convert hex to binary
To convert a hex value into binary, take each hex digit in turn.
Operations
AND, OR, XOR, NOT and the two shifts, with truth tables.
- Bitwise AND
The AND operation compares the two values bit by bit.
- Bitwise OR
The OR operation compares the two values bit by bit.
- Bitwise XOR
The XOR operation compares the two values bit by bit.
- Bitwise NOT
The NOT operation inverts every bit of one value.
- Left shift
A left shift moves every bit to a higher position.
- Right shift
A right shift moves every bit to a lower position.
Serial and registers
Plot live serial data and read a hardware register bit by bit.
- Serial plotter in the browser
Beetwise plots live serial data in a browser tab.
- UART debugger in the browser
Beetwise reads a UART stream and shows each value as a register.
- Register viewer
A register viewer shows every bit of a value at the same time.
- How to read a microcontroller register
A microcontroller register packs several fields into one value.