FAQ
TL;DR: Use divide‑by‑2 with remainders for integers and multiply‑by‑2 for fractions; 8 bits encode 256 values; “eight bits…values 0 through 255.” [Byte]
Why it matters: You’ll convert numbers correctly for coding, embedded debugging, exams, and interviews.
Quick Facts
- Decimal→binary (integers): repeatedly divide by 2, read remainders from last to first. [Binary number]
- Unsigned 8‑bit range: 0–255; signed (two’s‑complement) 8‑bit: −128–127. [Two's complement]
- Decimal 0.1 cannot be represented exactly in binary floating point; expect rounding artifacts. [Floating-point arithmetic]
- Excel: =DEC2BIN(number,[places]); valid inputs −512…511; negatives returned as 10‑bit two’s‑complement. [DEC2BIN function - Microsoft Support]
- Python: bin(x) returns a '0b'‑prefixed binary string (e.g., bin(42) -> '0b101010'). [Built-in Functions — Python 3.14.0 documentation]
What’s the general step‑by‑step way to convert a decimal integer to binary?
Use the division‑by‑2 method.
- Divide the decimal number by 2 and note the remainder (0 or 1).
- Repeat with the quotient until it becomes 0.
- Read remainders in reverse order to get the binary.
Example: 13 → remainders 1,0,1,1 → 1101. [Binary number]
How do I convert a decimal fraction (like 10.625) to binary?
Split integer and fractional parts. Convert the integer via division‑by‑2. For the fraction, repeatedly multiply by 2; each product’s integer part becomes the next bit. Stop when the fraction is 0 or you reach needed precision. Example: 0.625 → 0.101. [Binary number]
How are negative decimals represented in binary?
Most systems use two’s complement: keep positive numbers unchanged; to get −N, invert N’s bits and add 1. Range for 8‑bit signed is −128 to 127. Quote: “two’s complement is the most common method of representing signed integers.” [Two's complement]
What did the original poster ask in this thread?
They asked: “Is there any general technique for converting a decimal number to binary?” This FAQ answers that with clear steps and tools. [Elektroda, Xy-sa Rhea Bitonga, post #21672061]
How can I check my binary result quickly?
Expand bits by powers of two to reconvert: for 1101₂ compute 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8+4+0+1 = 13₁₀. This verifies correctness without a calculator. [Binary number]
What’s the fastest way to go between binary and hex during debugging?
Group binary into nibbles (4 bits) from the right; map each nibble to one hex digit. Since 16 = 2⁴, two hex digits equal one byte. This is lossless and quick for reading memory dumps. [Hexadecimal]
Why does 0.1 in code become 0.10000000000000001 sometimes?
Binary floating point cannot represent 0.1 exactly; operations round to the nearest representable value. Expect tiny errors like 0.1+0.2 = 0.30000000000000004. Quote: “0.1 and 0.01 cannot be represented exactly as binary floating‑point numbers.” [Floating-point arithmetic]
How do I convert in Excel or Google Sheets?
Use DEC2BIN. Example: =DEC2BIN(13) → 1101. Places pads with leading zeros: =DEC2BIN(5,8) → 00000101. Inputs must be −512…511; negatives return a 10‑bit two’s‑complement string. [DEC2BIN function - Microsoft Support]
How do I convert in Python?
Use bin(x) for integers. Example: bin(42) → '0b101010'; strip the prefix via bin(42)[2:]. For padding, use format(42, '08b') → '00101010'. This is built into Python and needs no imports. [Built-in Functions — Python 3.14.0 documentation]
What’s LSB vs. MSB when reading binary results?
LSB is the least significant bit (2⁰, rightmost). MSB is the most significant bit (highest power of two, leftmost). Reading remainders backward in the divide‑by‑2 method reconstructs MSB…LSB order. [Binary number]
Does endianness change how I write binary digits?
Endianness changes byte order in memory, not the order of bits within each byte. When you write a byte like 01101010, its internal bit order stays the same; systems may store bytes LE or BE. [Endianness]
What’s the maximum value in one byte, and why is it everywhere?
One byte (8 bits) has 2⁸ = 256 possible values, ranging from 0 to 255. You’ll see 255 in RGB channels, IPv4 octets, and many device registers. [256 (number)]
Give me a real‑world size reference for binary ranges.
A 32‑bit unsigned integer stores values 0 to 4,294,967,295. That’s why 32‑bit systems historically cap directly addressable space at 4 GiB. Statistic: 2³²−1 = 4,294,967,295. [32-bit computing]
What edge cases should I watch when converting or negating values?
In two’s complement, the most negative value (e.g., −128 in 8‑bit) cannot be negated; it overflows to itself. Detect this during tests to avoid wraparound bugs. [Two's complement]
Can I drop or add leading zeros to a binary number?
Yes. Leading zeros do not change value: 00101101₂ equals 101101₂. Padding to fixed widths (8, 16, 32 bits) improves readability and alignment in tools. [Binary number]
Is there a one‑line mental method to convert small decimals?
Find the largest power of two ≤ N, set that bit, subtract, and continue. Example: 23 → 16+4+2+1 → 10111₂. This mirrors positional weights in binary. [Binary number]