Number Base Calculator

Convert instantly between binary, octal, decimal and hexadecimal, with a live bit-pattern diagram.
Convert

Convert Between Number Bases

Any base value = Σ (digit × baseposition)
255 (decimal)
11111111 (binary)
FF (hex)
A5 (hex)
Enter a value and press Convert.

Bit Pattern (live — shows binary place values)

The Four Number Bases Electronics Uses

Every number base represents the same quantity, just grouping digits differently. Decimal (base 10) is what humans use daily. Binary (base 2) is what digital hardware actually stores and computes with — every bit is either 0 or 1, matching a transistor's on/off state. Hexadecimal (base 16) is a compact shorthand for binary, since each hex digit represents exactly 4 bits (a "nibble") — making it far easier for humans to read and write long binary values like memory addresses or register contents. Octal (base 8), where each digit represents exactly 3 bits, was more common in older computing systems and is still occasionally seen in Unix file permissions.

BaseDigits usedBits per digitTypical use
Binary0-11What hardware actually stores/computes
Octal0-73Unix file permissions, legacy systems
Decimal0-9—Everyday human-readable numbers
Hexadecimal0-9, A-F4Memory addresses, register values, color codes

Real-World Applications & Fully-Explained Examples

Worked examples — explained in full

1. 255 (decimal) to binary, octal and hex. Binary=11111111 (eight 1-bits, the maximum value for a byte). Octal=377. Hex=FF — the maximum value representable in one byte (8 bits) in any base.
2. 11111111 (binary) to decimal. 128+64+32+16+8+4+2+1=255 — summing each bit's place value (each a power of 2) where the bit is 1.
3. 1010 (binary) to decimal and hex. Decimal: 8+0+2+0=10. Hex: A (since hex digit A represents decimal 10).
4. FF (hex) to decimal and binary. Decimal: F×16+F=15×16+15=240+15=255. Binary: 11111111 — consistent with example 1, confirming FF, 255, and 11111111 all represent the identical value.
5. A5 (hex) to decimal. A×16+5=10×16+5=160+5=165.
6. 777 (octal, common Unix "full permissions" value) to decimal. 7×64+7×8+7×1=448+56+7=511 — representing "read+write+execute" permission bits for owner, group, and others all set.

Why Embedded Work Lives in Hexadecimal

Hexadecimal is not used because programmers enjoy it — it is used because one hex digit maps exactly to four bits. That makes the translation between a human-readable number and the underlying bit pattern purely mechanical, with no arithmetic involved.

Decimal has no such relationship. The byte 0xA5 is instantly readable as 1010 0101, but its decimal form, 165, tells you nothing about which bits are set. Since microcontroller registers are defined bit by bit, hexadecimal is simply the notation that matches the hardware.

BinaryHexDecimal
0000 00000x000
0000 11110x0F15
1010 01010xA5165
1111 11110xFF255

Masks, and why they are written in hex

Setting, clearing and testing individual bits is the daily work of register programming. Writing REG |= 0x08 to set bit 3, or REG &= ~0x08 to clear it, is readable precisely because 0x08 is visibly a single bit in position 3. The decimal equivalent, 8, happens to be just as clear here — but 0x40 versus 64, or 0x2000 versus 8192, is where the advantage becomes obvious.

Two’s complement and the negative-number surprise

Signed integers are stored in two’s complement, where the top bit carries negative weight. In an 8-bit signed value, 0xFF is −1 rather than 255, and the range runs from −128 to +127 instead of 0 to 255.

This is the source of a whole family of bugs. Reading a sensor into a signed variable when the data is unsigned turns large readings negative; mixing signed and unsigned types in a comparison can make a loop run the wrong way or never terminate. The usual discipline is to use explicitly sized types — uint8_t, int16_t — so the width and signedness are stated rather than inferred.

Octal survives mainly in Unix file permissions, where three bits per digit maps neatly onto the read, write and execute triplet.

Frequently Asked Questions

How do I convert binary to decimal?

Multiply each bit by its place value (a power of 2, starting from 2^0 on the right) and add the results. For example, 1010 = 1×8 + 0×4 + 1×2 + 0×1 = 10.

How do I convert hex to decimal?

Multiply each hex digit by its place value (a power of 16) and add the results, using A=10, B=11, C=12, D=13, E=14, F=15 for the letter digits. For example, FF = 15×16 + 15 = 255.

Why does electronics use hexadecimal instead of just binary?

Hexadecimal is a compact, human-readable shorthand for binary — each hex digit represents exactly 4 bits, so an 8-bit byte becomes just 2 hex digits (e.g. 11111111 = FF) instead of 8 hard-to-read binary digits.

What is the maximum value of a single byte?

255 in decimal, FF in hex, 11111111 in binary, and 377 in octal — all the same value, representing all 8 bits set to 1.

How do I convert octal to decimal?

Multiply each octal digit by its place value (a power of 8) and add the results. For example, 777 (octal) = 7×64 + 7×8 + 7×1 = 511.

What does a hex color code like #FF5722 mean?

It encodes red, green, and blue intensity as three hex byte pairs: FF (255, full red), 57 (87, some green), 22 (34, a little blue) — each pair ranges from 00 (none) to FF (255, maximum) for that color channel.

Why do Unix file permissions use octal (like chmod 755)?

Because each of the three permission groups (owner, group, others) uses exactly 3 bits (read/write/execute), and octal digits represent exactly 3 bits each — making one octal digit per permission group a natural, compact fit.

What is the largest number a given number of bits can represent?

2^n - 1 for n bits (unsigned): 1 bit gives 0-1, 4 bits give 0-15, 8 bits give 0-255, 16 bits give 0-65,535, and so on — each added bit doubles the range of representable values.

Do negative numbers work the same way in binary?

Not directly — computers most commonly use "two's complement" representation for signed (negative-capable) binary numbers, which is a specific encoding scheme beyond simple base conversion; this calculator handles unsigned (non-negative) base conversion.

How do I quickly convert hex to binary without full decimal conversion?

Convert each hex digit individually to its 4-bit binary equivalent and concatenate them — since each hex digit maps to exactly 4 bits, there's no need to go through decimal at all (e.g. hex "A5" = binary "1010" + "0101" = "10100101").

Why is hexadecimal used in programming?

Because one hex digit corresponds to exactly four bits, so converting between hex and the underlying bit pattern needs no arithmetic. Decimal has no such alignment with binary.

How do I convert hex to binary?

Translate each hex digit into its four-bit group independently. 0xA5 becomes 1010 0101, since A is 1010 and 5 is 0101.

What is a bit mask?

A value used to isolate or modify specific bits. OR with a mask sets those bits, AND with its complement clears them, and AND with the mask tests them. Masks are written in hex because the bit positions are then visible at a glance.

What is two's complement?

The standard representation for signed integers, in which the most significant bit carries negative weight. In 8 bits, 0xFF represents −1 and the range is −128 to +127 rather than 0 to 255.

Why does my sensor reading go negative unexpectedly?

Usually because unsigned data has been stored in a signed variable. Any value with the top bit set is then interpreted as negative. Using explicitly sized types such as uint16_t avoids the ambiguity.

Where is octal still used?

Mainly in Unix file permissions, where each octal digit represents exactly three bits and maps onto the read, write and execute permission triplet.

Related Calculators

Scientific Calculator • ADC Resolution Calculator • All Calculators

Vinay Singh, author of this page

Written and reviewed by

Lead Electronic Engineer (R&D) · Power Electronics Specialist · M.E. Power Electronics

Founder of Power4All. Works in power-electronics R&D and writes the converter guides, calculators and simulators on this site.

Last updated

Recommended Components & Tools