Decimal to Binary Converter
Convert decimal (base 10) numbers to binary (base 2).
Binary
Decimal to binary, explained
Binary is the base-2 number system computers use internally: every value is expressed with just the digits 0 and 1. To convert a decimal number, repeatedly divide by 2 and read the remainders bottom-up — e.g. 42 becomes 101010. This tool handles arbitrarily large integers and converts every line locally in your browser — nothing is uploaded.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Building a bitmask from a decimal value and checking which bits it sets.
- Producing a binary constant for a register write or a configuration field.
- Checking whether a number is a power of two from its bit pattern.
- Working out how many bits a value needs before choosing a field width.
- Producing a bit pattern for a teaching example or a datasheet.
Frequently Asked Questions
- How do I convert by hand?
- Divide by 2 repeatedly and read the remainders bottom-up, or subtract the largest fitting power of two in turn. For 13: 8 + 4 + 1, giving 1101. The second method is faster once you know the powers.
- How are fractions represented?
- By negative powers of two: 0.5 is 0.1, 0.25 is 0.01. This is why 0.1 decimal is a REPEATING binary fraction and cannot be stored exactly — the root cause of 0.1 + 0.2 === 0.30000000000000004 in almost every language.
- How many bits does a number need?
- floor(log2(n)) + 1. Values up to 255 need 8 bits, up to 65535 need 16, up to ~2.1 billion need 32 signed. Exceeding the width wraps silently in most languages rather than raising an error.
- How are negative values encoded?
- Two's complement: invert the bits and add one. The leading bit carries a negative weight, which is why an 8-bit signed range is −128 to 127 rather than symmetric — there is one more negative value than positive.
- Why are powers of two everywhere in computing?
- Because each additional bit doubles the addressable range. Memory sizes, buffer lengths and array capacities land on 256, 1024, 4096 for that reason, not by convention — it is what binary addressing produces naturally.
- How is a fraction converted by hand?
- By repeatedly multiplying by two and taking the integer part as the next bit. The process terminates only when the fraction is a sum of powers of two, which is why 0.1 never terminates in binary.
- What does a bit shift do to the value?
- Each left shift doubles it and each right shift halves it, discarding the shifted-out bit. That is why shifts are used in place of multiplication by powers of two, and why an unintended shift changes a value by orders of magnitude.
Common errors and gotchas
- Not padding to the field width, so bit positions shift when the value is placed in a register.
- Converting a negative number without fixing the width, which two's complement requires.
- Converting a fractional part and expecting termination, which most decimal fractions do not have.
- Assuming the output is byte-aligned, when it is only as long as the value needs.
- Producing more bits than the target field holds and having the top ones silently dropped.
Related Converters tools
JSON to YAML
Convert JSON into clean, readable YAML instantly.
YAML to JSON
Convert YAML configuration into valid JSON.
JSON to XML
Convert JSON structures into nested XML markup.
HWB to HEX Converter
Convert an HWB color to HEX.
JSON to SQL
Turn a JSON array of objects into SQL INSERT statements.
CSV to XML
Convert CSV rows into structured XML records.
XML to CSV
Flatten repeated XML records into CSV rows.
INI to JSON
Parse INI config sections and keys into JSON.