UAC

Binary and Hex: Understanding Number Bases

Everything a computer stores is binary. But humans rarely read binary directly β€” which is why hex and octal exist. Here is how all four bases connect.

5 min readUpdated March 1, 2026by Samir Messaoudi

Why Number Bases Matter in Computing

Everything a computer processes is ultimately stored as binary β€” sequences of 0s and 1s representing electrical off and on states. Humans rarely interact with binary directly because it is unwieldy: the decimal number 1,000 requires 10 binary digits (1111101000). This gap between how computers represent data and how people prefer to work with numbers created two bridging systems: hexadecimal (base-16) and octal (base-8).

Hexadecimal is the dominant alternative in modern computing. Each hex digit represents exactly four binary bits, so one byte (8 bits) becomes exactly two hex digits. This compactness makes hex the standard for memory addresses (0x7FFF), web color codes (#1A2B3C), MAC addresses (00:1A:2B:3C:4D:5E), and system error codes. When you see a Windows stop code like 0xC0000005, that is a hex representation of a 32-bit memory access violation code.

Octal (base-8) is used primarily in Unix and Linux systems for file permissions. The chmod 755 command represents three groups of binary permission bits β€” read (4), write (2), execute (1) β€” combined in octal. Understanding this connection makes Unix permissions immediately readable rather than requiring memorization of magic numbers.

Convert any number between bases

Enter any decimal, binary, octal, or hex value to get all four representations with step-by-step conversion work shown.

Open Number Converter

How to Convert Between Number Bases

  1. 1

    Decimal to binary: repeated division by 2

    Divide the decimal number by 2 repeatedly, recording the remainder (0 or 1) at each step. Read remainders bottom to top. Example: 42 gives remainders 0,1,0,1,0,1 β€” binary 101010.

  2. 2

    Binary to decimal: sum powers of 2

    Each binary position is a power of 2 reading right to left from position 0. 101010 has 1s at positions 1, 3, and 5 β€” giving 2 plus 8 plus 32 = 42.

  3. 3

    Decimal to hex: repeated division by 16

    Divide by 16, recording remainders as hex symbols (A-F for values 10-15). Read bottom to top. 255 divided by 16 gives remainder 15 twice β€” both are F, so result is FF.

  4. 4

    Hex to binary: expand each digit to 4 bits

    Each hex digit expands to exactly 4 binary bits β€” no arithmetic required. 1A becomes 0001 1010 in binary (26 decimal). This is the fastest conversion for large hex values.

  5. 5

    Octal to binary: expand each digit to 3 bits

    Each octal digit maps to exactly 3 binary bits. Octal 755 = 111 101 101, immediately showing the Unix rwx r-x r-x permission pattern for owner, group, and others.

Where You Encounter Each Base

Binary appears when working with bitwise operations in code, reading CPU registers in a debugger, understanding boolean logic circuits, and interpreting network subnet masks at the bit level. Bitwise operators (AND, OR, XOR, NOT, shift) are clearest when values are visualized as binary.

Hexadecimal dominates software development. CSS and HTML color codes (#RRGGBB) are three pairs of hex digits. Memory addresses in debuggers are always hex. Windows BSOD stop codes and Unix signal numbers are typically hex. MAC addresses on network interfaces use hex pairs separated by colons.

Octal appears in Unix file system contexts (chmod, umask) and in C-family languages where an integer literal with a leading zero is interpreted as octal β€” a source of subtle bugs when developers accidentally prefix a decimal number with 0.

Frequently Asked Questions

When would I actually need to convert between bases?

+

Common situations: reading memory addresses in a debugger (always hex), understanding Unix permissions (chmod 755 means rwx r-x r-x in binary), decoding web color codes (#1A2B3C hex), interpreting subnet masks, reading CPU registers in assembly output, and using bitwise operations in any programming language.

What is two's complement and why does it matter?

+

Two's complement is how computers represent negative integers in binary. For 8-bit signed integers, the most significant bit represents -128 rather than +128. To find the two's complement: flip all bits and add 1. This allows addition and subtraction to work identically for positive and negative numbers using the same hardware circuits.

What is the difference between signed and unsigned integers?

+

Unsigned integers treat all bits as magnitude β€” 8-bit unsigned ranges from 0 to 255. Signed integers dedicate the most significant bit as sign β€” 8-bit signed ranges from -128 to +127. The pattern 11111111 means 255 unsigned and -1 signed. Specifying type correctly is critical when operating on binary data.

Why does 0x indicate hexadecimal in code?

+

The 0x prefix is a C language convention adopted by most modern languages including C++, Java, Python, JavaScript, and Rust. The leading 0 signals to the parser that a non-decimal numeric literal follows, and the x specifies hexadecimal base. Python additionally uses 0b for binary (0b1010 = 10) and 0o for octal (0o17 = 15). In assembly language, hex is often indicated by a trailing h suffix instead (FFh). The convention exists to prevent ambiguity when hexadecimal digits overlap with decimal ones.

How does bit shifting relate to multiplication?

+

Left shift by n positions multiplies by 2 to the power n. Right shift by 1 performs integer division by 2. CPUs execute bit shifts in a single clock cycle, making them faster than general multiplication for powers of two β€” a common low-level optimization.

How do hex color codes work?

+

A CSS hex color like #1A2B3C has three 2-digit hex pairs: 1A for Red (26 decimal), 2B for Green (43), 3C for Blue (60). Each channel ranges from 00 (zero) to FF (255, maximum). #000000 is black, #FFFFFF is white, #FF0000 is pure red. The shorthand #ABC expands to #AABBCC.

Convert any number between bases

See decimal, binary, octal, and hex simultaneously with step-by-step conversion work.

Open Number Converter