Number Systems ยท Dev Tools

Binary Converter

Convert text, decimal numbers, and hex values to binary โ€” and back. See exactly what each bit represents, with clean 8-bit grouping and instant results.

What is binary, and why does it exist?

Binary is base-2 arithmetic: every value is expressed using only the digits 0 and 1. Computers use it because the underlying hardware โ€” transistors โ€” operates in two states: off (0) and on (1). There's no practical way to reliably distinguish ten voltage levels in a circuit, but two is straightforward and noise-resistant.

Everything a computer does โ€” arithmetic, text rendering, networking, audio playback โ€” ultimately reduces to patterns of 0s and 1s moving through circuits. Higher-level abstractions like decimal numbers, text encodings, and color codes are all representations that get converted to binary before the hardware touches them.

You rarely need to think in binary for day-to-day development, but certain tasks make it unavoidable: reading network packet headers, debugging bitwise flags in configuration registers, analyzing memory dumps, or understanding why floating-point arithmetic produces unexpected results.

How each conversion type works

Text โ†’ Binary

Each character is first mapped to a number via an encoding standard โ€” ASCII for basic Latin text, UTF-8 for anything beyond that. That number is then converted to base-2 and padded to 8 bits. The results are concatenated in order.

char โ†’ H โ†’ ASCII 72 โ†’ 01001000
char โ†’ i โ†’ ASCII 105 โ†’ 01101001
"Hi" โ†’ 01001000 01101001

Decimal โ†’ Binary

Divide the decimal number by 2 repeatedly, recording the remainder at each step. Read the remainders from bottom to top. This is the standard long-form method โ€” the tool does this automatically, but understanding it helps when reading binary output.

42 รท 2 = 21 remainder 0
21 รท 2 = 10 remainder 1
10 รท 2 = 5 remainder 0
5 รท 2 = 2 remainder 1
2 รท 2 = 1 remainder 0
1 รท 2 = 0 remainder 1
42 โ†’ 00101010(read remainders bottom-up)

Hexadecimal โ†’ Binary

This is the most mechanical of the three conversions. Each hex digit maps to exactly 4 binary digits (a nibble), with no overlap or carry. You can do it character by character.

Hexโ†’Decimalโ†’ Binary
Aโ†’101010
Fโ†’151111
0โ†’00000
9โ†’91001
0xAF โ†’ 10101111

Who uses binary conversion, and for what

Binary conversion comes up in more contexts than most developers expect. Here are the recurring situations where it's genuinely needed.

๐Ÿ“ก

Network and subnet analysis

IP addresses and subnet masks are fundamentally binary. A /24 subnet mask is 11111111.11111111.11111111.00000000. Understanding which bits are "network" vs "host" bits requires reading them in binary โ€” CIDR notation is just a shorthand for bit counts.

๐Ÿ”ง

Bitwise flags in configuration

Many APIs and system calls pack multiple boolean options into a single integer using bitwise flags. Converting the integer to binary immediately shows which flags are set. Linux file permissions (chmod 755 = 111 101 101) are a familiar example.

๐ŸŽ›๏ธ

Embedded systems and firmware

Microcontroller registers are documented as binary bit fields. A UART control register might use bits 4โ€“6 for baud rate selection and bit 0 to enable the transmitter. Reading the register value in binary tells you exactly which features are active.

๐ŸŽ“

CS coursework and interview prep

Number system conversion โ€” binary, octal, decimal, hex โ€” is covered in most CS curricula and appears in technical interviews. Being able to do small conversions by hand, and verify them instantly with a tool, builds the intuition needed for bitwise algorithm problems.

๐ŸŒ

WebAssembly and binary protocols

WebAssembly modules are binary files. High-performance web applications use ArrayBuffer and DataView to work with raw binary data for things like audio processing, image manipulation, and WebSockets. Understanding the binary layout of your data is a prerequisite.

๐Ÿ”’

Cryptography and hashing

Hash functions, block ciphers, and key derivation algorithms operate at the bit level using XOR, AND, OR, and bit-shift operations. Tracing through a cryptographic algorithm step-by-step requires seeing the binary values at each stage.

Concepts worth understanding

Bits, nibbles, and bytes

A bit is a single 0 or 1. Four bits make a nibble (one hex digit). Eight bits make a byte, which is the standard unit of addressable memory. This tool groups output into bytes โ€” 8-bit blocks โ€” because that's how memory is organized and how most protocol documentation presents binary data.

Two's complement for negative numbers

Signed integers use two's complement encoding. To find the binary representation of โˆ’42: start with 42 (00101010), flip every bit (11010101), then add 1 (11010110). The most significant bit being 1 signals a negative number. This scheme means addition hardware works the same for positive and negative numbers โ€” no special case needed.

42 โ†’ 00101010
flip โ†’ 11010101
+1 โ†’ 11010110(= โˆ’42 in 8-bit signed)

Boolean operations on binary

Bitwise operators (AND, OR, XOR, NOT, shifts) are the primitive operations that make binary practically useful in code. Common patterns: using AND with a mask to check or clear specific bits, using OR to set bits, and using XOR to toggle them.

0b10110110 (check if bit 4 is set)
& 0b00010000 (mask)
= 0b00010000 (non-zero โ†’ bit 4 is set โœ“)

IEEE 754 floating-point

Decimal fractions like 0.1 can't be represented exactly in binary โ€” the value repeats infinitely in base-2, like 1/3 repeats in base-10. IEEE 754 specifies how computers store a close approximation using three fields: a sign bit (positive or negative), an exponent (the magnitude), and a mantissa (the significant digits). This is why 0.1 + 0.2 !== 0.3 in JavaScript โ€” it's a rounding artifact of binary floating-point, not a bug.

Practical tips

1
Memorize the powers of 2 up to 256. 1, 2, 4, 8, 16, 32, 64, 128, 256. Once these are automatic, you can estimate binary values mentally. You'll immediately recognize that 11000000 is 128 + 64 = 192 without working it out step-by-step.
2
Use hex as your readable shorthand. When working with binary data in code, convert to hex for display and logging. A 64-bit value is 64 characters in binary but only 16 in hex. Memory addresses, byte arrays, and color values all become much more manageable.
3
Watch the sign bit when working with signed integers. In an 8-bit signed integer, 11111111 is โˆ’1, not 255. If you're seeing unexpected negative values when converting binary output, check whether your language is treating the type as signed or unsigned. The binary digits are identical; the interpretation differs.
4
Check bit order when reading hardware documentation. Datasheets often specify whether bit 0 is the most significant bit (MSB) or least significant bit (LSB). If a register description lists bits from left to right as 7 6 5 4 3 2 1 0, bit 7 is the MSB. Misreading bit order is a common firmware bug.

Frequently asked questions

How is text converted to binary?+

Each character is mapped to a number using ASCII or UTF-8 encoding, then that number is expressed in base-2 and padded to 8 bits. The letter A is ASCII 65, which is 01000001 in binary. The letter B is 66 = 01000010. For a string like "Hi", you get two 8-bit groups concatenated: 01001000 01101001.

Why is the output grouped in sets of 8?+

Eight bits form one byte โ€” the standard unit of memory addressing. Nearly all hardware and protocol documentation presents binary data in bytes. Grouping this way makes it far easier to map binary output back to specific characters, values, or fields.

How are negative numbers represented?+

Most systems use two's complement. Take the positive binary value, flip all bits, then add 1. The result has a 1 in the most significant bit, which signals that it's negative. This lets the same addition circuit handle both positive and negative numbers without any special cases.

Why use hex instead of binary for large values?+

Binary is verbose. A 32-bit integer is 32 characters; in hex it's 8. Since every 4 binary digits map exactly to one hex digit, the conversion is lossless and mechanical. Memory addresses, byte arrays, and color codes are all conventionally displayed in hex for exactly this reason.

Is binary still relevant for web development?+

More than most people realize. The Web Crypto API, WebAssembly, Canvas image data, WebSockets with binary frames, and file reading via FileReader all work with binary data directly. If you've ever used ArrayBuffer, DataView, or Uint8Array, you've been working with binary.

Feedback

Live