Computers · digital

Bit Calculator

Binary, hex, octal and decimal — plus the two conversions that actually catch people out: 1000 versus 1024, and bits versus bytes.
two's complement · BigInt
0xB4 · 8-bit

Value

one number, four notations — edit any and the rest follow · what are they?8-bit
bits
HEX
OCT
DEC
BIN

Bit grid

click any bit to flip it0xB4

Every number a computer holds is a row of switches, each either on (1) or off (0). Each switch is worth double the one to its right, so the row below is the number — the four boxes on the left are just four ways of writing it down. Click any switch to change it and watch all four move.

Read direction
Bit 0 sits
Group every
Lanes
Repeats
Repeats sit
Unused bits
Operations
bit = 1 bit = 0 —
At a glance
Sizes

Why a 1 TB drive shows up as 931 GB

the same bytes, counted two different ways
—
shortfall against the binary unit

Neither number is wrong. The drive really does hold a million million bytes; Windows really is dividing by 1024 three times and calling the answer GB. The two families were reconciled in 1998 — IEC 80000-13 gave the binary ones their own names (kibi, mebi, gibi) — and almost nobody adopted them, so the same three letters still mean two things about 7% apart at terabyte scale. macOS and Linux report decimal GB; Windows reports binary and labels it GB.

Rates

Your 100 Mbps line does not move 100 MB a second

the factor of eight, and what is left after overhead
—
if you read Mbps as MB/s ÷8, the arithmetic answer after overhead
Bitwise lab

Combine two values, bit by bit

columns line up so you can see each result bit form
0x
0x
The four bases

What decimal, hex, octal and binary actually are

Every one of them is the same idea: a row of digits where each place is worth a fixed multiple of the place to its right. What changes is the multiple — ten, sixteen, eight or two — and that single choice decides everything else about how the notation behaves.

Why 4 bits is one hex digit, and 3 bits is one octal digit

Sixteen is 24 and eight is 23. That is the whole reason both bases exist. Because the base is a power of two, a fixed block of bits maps onto exactly one digit and nothing ever carries between blocks — you can read a hex digit off four bits without looking at any of the others, and write it back the same way.

Ten is not a power of two. So there is no block of bits that corresponds to a decimal digit, no way to read one off without considering the whole number, and converting to decimal is the only one of the four that requires actual division. It is why a programmer reads 0xB4 off a byte at a glance and has to think about 180.

Hex won because 4 divides 8: two hex digits are exactly one byte, forever. Octal does not — three bits do not divide eight, so the top octal digit of a byte is always a stunted two-bit one. Octal made perfect sense on the 12, 18 and 36-bit machines that came before bytes settled at eight, and it survives mostly in Unix file permissions, where the fields genuinely are three bits wide: read, write, execute.

Reading a number in any base

Take the digits from the right. The rightmost is worth 1, the next is worth the base, the next the base squared, and so on. Multiply each digit by its place and add them up. That is the entire algorithm, and it is identical in all four:

BasePlaces, right to leftDigits usedBits per digit
Binary (2)1, 2, 4, 8, 16, 32…0–11
Octal (8)1, 8, 64, 512…0–73
Decimal (10)1, 10, 100, 1000…0–9—
Hex (16)1, 16, 256, 4096…0–9, A–F4

The bits per digit column is the useful one. It is blank for decimal because there is no answer — and that blank is the practical difference between the bases a computer person uses and the one everybody else does.

How it works

One number, four ways to write it

Bits, nibbles, bytes

A bit is one 0/1. Four make a nibble (one hex digit); eight a byte (two hex digits, 0–255). Word sizes are stacks of bytes: 8, 16, 32 or 64 bits.

Why hex

Each hex digit is exactly one nibble, so binary and hex swap 4-to-1 with no arithmetic. 0xB4 is 1011 0100 at a glance.

Masking and wrap-around

Fixed word sizes drop anything above the top bit, so values wrap modulo 2n. Every result is masked to the word size, like a CPU register: 255 + 1 = 0 in a byte.

Bitwise logic

AND keeps bits set in both, OR in either, XOR where they differ. The building blocks of flags, masks and permissions; the lab shows each result bit forming column by column.

Worked example. The byte 0xB4 is 180 unsigned, or −76 signed because its top bit is set: the bits do not change, only how the decimal is read. In binary it is 1011 0100, four bits set. Flip the top bit and the unsigned value drops by 128; NOT it and you get 0x4B (75). In the lab, 0xF0 AND 0x3C keeps only the bits set in both: 0x30. Bars are on a scale of 255.
Field notes

The ideas behind the bits

Left-to-right is a convention, not a fact

Almost every diagram puts the most significant bit on the left, because that is how we write numbers. Serial links shift out least-significant-first, bit-reversed FFT orders exist for a reason, and plenty of datasheets number from the other end. Reading a diagram the wrong way round is one of the easier ways to lose an afternoon.

There are two controls because they are two questions: read direction (which end the word is read from, and the order bits are dealt round the lanes) and where bit 0 sits (only the drawing). Neither changes the value, and neither is the same as reversing the bits, which does.

26bits

Widths that are not whole bytes

A 26-bit field, a 12-bit ADC reading, a 20-bit address bus, a 5-bit register field: a grid built from byte rows cannot draw any of them. A 26-bit value needs seven hex digits, and was once padded to six and a half, so the top two bits fell off the readout. Byte swap is now off below a whole byte, because with no bytes to reverse a control that looks available is worse than one that is visibly off.

1,800combinations

Every n-th bit, not the next n bits

Interleaved data is dealt round its consumers one bit at a time: RAID stripes, memory channels, SIMD lanes, LED driver chains. Lane i gets positions i, i+n, i+2n, so what one consumer sees is scattered through the word. When the lane count does not divide the width the last lanes come up one bit short, drawn rather than padded, because that asymmetry is what bites. The dealing is checked by dealing the bits out and picking them back up at every width from 1 to 64 and every lane count from 1 to 12, both directions: 1,800 combinations, each returning the value it started with.

Questions

What people ask

Why does the value wrap when I overflow?

A word size is a fixed number of bits. Anything past the top bit has nowhere to go, so it's dropped — the value "wraps" modulo 2ⁿ. That's exactly what a CPU register does, and it's why 255 + 1 = 0 in a byte.

What's two's complement?

The standard way to store negative integers: the top bit carries a negative weight. In a byte, values 0–127 are themselves; 128–255 represent −128 to −1. Switch to signed to see it — the bits don't change, only how the decimal is read.

Hex vs octal — why hex won?

One hex digit maps to exactly four bits (a nibble), so a byte is two clean hex digits. Octal packs three bits per digit, which doesn't line up with 8-bit bytes — handy for old systems and Unix permissions, but hex fits modern hardware better.

How is 64-bit handled correctly?

JavaScript's normal bitwise operators only work on 32 bits. This tool uses BigInt for everything, so 64-bit shifts, rotates and masks are exact — no silent truncation.

What this page assumes

The bit grid and bitwise lab take whole numbers only — no fractions and no floating point, which has an entirely different bit layout. The size and rate sections further down are ordinary decimal arithmetic and do accept fractions. Signed values use two’s complement, and the selected word size wraps around rather than reporting an error, exactly as hardware does. Byte order (endianness) does not appear here at all: it affects how a value is laid out in memory or sent over a wire, not what the value is.

Exact, arbitrary-width integer math. Values are masked to the selected word size using two's-complement rules — the same wrap-around real hardware does.
Version history · 11 releases
  1. v4.822026-09-09The bit grid learned to repeat, to ghost the bits a short word wastes, and to explain what decimal, hex, octal and binary actually are
  2. v4.832026-09-09Typing a custom word width destroyed the value on the first keystroke, and the 32-bit row was in a column half wide enough to show it
  3. v4.842026-09-09The bit calculator’s two-column layout was never written down, so editing it collapsed the sidebar — rebuilt on purpose, with smaller cells that fit 32 bits on one line
  4. v4.852026-09-09The bit calculator’s config bar was a five-column grid using two of them — 640px of it empty. Laid out on twelve, by what each value is actually as long as
  5. v4.862026-09-09The word-size presets and the any-width box are one control, so they now sit on one line
  6. v5.312026-09-13The bit grid: reading direction and the end bit 0 sits at are two controls now, not one doing both jobs; the repeats stopped reading backwards; and the lanes are one grid, so every lane's columns line up and a repeat is separated by a dotted rule in a column of its own
  7. v5.372026-09-13The bit grid: the row is sized from the box so nothing scrolls sideways at any width, the repeat rule sits in the gap instead of shoving the columns, the bits are justified on bit 0, and the lanes line up with the word exactly
  8. v5.382026-09-14The bit grid: repeats grow away from bit 0 instead of shoving it, the cut between passes is a staircase drawn in the gaps the grid already has, the unused bits show in every pass, and nothing on the page scrolls sideways at any width
  9. v5.392026-09-14The bit grid: a repeat is the next line down, not a dotted rule threaded through the same row — which puts the word back at the top, doubles the size of the lane cells, and deletes the staircase, the jogs and the chunking that existed to prop the old layout up
  10. v5.412026-09-14The bit grid: the word chooses whether a repeat takes a line of its own or carries on behind a marker; the lanes pack, which bends the join into an L and makes the round numbering count straight through
  11. v6.92026-09-27Bit calculator neatened: bigger bits, colour-keyed notations, a decimal panel in the bases diagram, and no lopsided cards

Releases in which this page changed, newest last. Derived from the archived copy of every release, not from notes written afterwards — so it reflects what actually shipped. Site-wide passes are left out; they are in the full changelog.

Rules of thumb are approximations, offered to get you to the right order of magnitude fast. Check anything load-bearing against its source or the exact tool. Privacy · Terms

© 2026 Rules of Thumb · Runs entirely in your browser