Tool Point

    Decimal to Binary Converter

    Convert decimal numbers (base-10) to binary numbers (base-2)

    Decimal to Binary Converter

    Enter a decimal number to convert it to binary

    Decimal to Binary Conversion

    • Binary numbers use only digits 0 and 1
    • Each position represents a power of 2
    • Example: 10 in decimal = 1010 in binary (1×8 + 0×4 + 1×2 + 0×1)

    Category Essentials

    Number tools often serve connected search intents like conversion, formatting, and basic math references. These featured pages help users move between the main number tasks more naturally.

    Daily Inspiration

    The pen is mightier than the sword. - Edward Bulwer-Lytton

    Decimal to Binary Converter: Convert Base 10 to Base 2

    Convert decimal numbers to binary instantly with our free decimal to binary converter. Whether you're learning computer science, programming, or working with digital systems, this tool helps you convert base 10 numbers to base 2 (binary) format quickly and accurately.

    Enter any decimal number (positive or negative, integer or fraction) to see the binary representation. Perfect for students, programmers, and anyone working with number systems.

    What Is a Binary Number (Base 2)?

    Binary is the base 2 number system, using only two digits: 0 and 1. It's the fundamental number system used by all digital computers and electronic systems.

    Binary vs Decimal

    Decimal (Base 10):

    • Uses digits 0-9
    • Each position represents a power of 10
    • Example: 253 = (2 x 102) + (5 x 101) + (3 x 100)

    Binary (Base 2):

    • Uses only digits 0 and 1
    • Each position represents a power of 2
    • Example: 1101 = (1 x 23) + (1 x 22) + (0 x 21) + (1 x 20)

    Why Binary Matters

    Digital electronics:

    • Computers process information in binary
    • Electronic circuits have two states: on (1) or off (0)
    • All data (numbers, text, images, sound) stored as binary

    Fundamental to computing:

    • Machine language uses binary
    • Memory addresses in binary
    • CPU operations work with binary
    • Network protocols use binary

    Binary Terminology

    Bit: A single binary digit (0 or 1)

    • Smallest unit of computer data
    • Short for "binary digit"

    LSB (Least Significant Bit):

    • Rightmost bit
    • Represents the smallest place value (20 = 1)
    • Example: In 1101, LSB is 1

    MSB (Most Significant Bit):

    • Leftmost bit
    • Represents the largest place value
    • Example: In 1101, MSB is 1 (represents 23 = 8)
    • In signed numbers, often indicates sign (0 = positive, 1 = negative)

    Byte: 8 bits

    • Common unit of computer storage
    • Can represent 0-255 in unsigned binary
    • Example: 11111111 = 255

    How to Convert Decimal to Binary (Step-by-Step)

    The standard method for converting decimal integers to binary is the successive division by 2 method.

    Division by 2 Method (For Integers)

    Algorithm:

    1. Divide the decimal number by 2
    2. Record the quotient and remainder
    3. Divide the quotient by 2
    4. Repeat until quotient is 0
    5. Read remainders from bottom to top

    Example 1: Convert 13 to Binary

    Step-by-step process:

    StepDivisionQuotientRemainder
    113 / 261
    26 / 230
    33 / 211
    41 / 201

    Read remainders from bottom to top: 1101

    Verification:

    • 1101 in binary = (1 x 8) + (1 x 4) + (0 x 2) + (1 x 1)
    • = 8 + 4 + 0 + 1 = 13

    Example 2: Convert 25 to Binary

    Step-by-step process:

    StepDivisionQuotientRemainder
    125 / 2121
    212 / 260
    36 / 230
    43 / 211
    51 / 201

    Read remainders from bottom to top: 11001

    Verification:

    • 11001 = (1 x 16) + (1 x 8) + (0 x 4) + (0 x 2) + (1 x 1)
    • = 16 + 8 + 0 + 0 + 1 = 25

    Example 3: Convert 255 to Binary

    Step-by-step process:

    StepDivisionQuotientRemainder
    1255 / 21271
    2127 / 2631
    363 / 2311
    431 / 2151
    515 / 271
    67 / 231
    73 / 211
    81 / 201

    Result: 11111111 (eight 1s)

    Note: 255 is the maximum value that fits in 8 bits (1 byte).

    Why This Method Works

    Each division by 2:

    • Extracts one bit at a time
    • Remainder is either 0 or 1 (the bit value)
    • Quotient becomes the next number to process

    Reading bottom to top:

    • First remainder is LSB (least significant bit)
    • Last remainder is MSB (most significant bit)
    • This naturally places bits in correct positions

    Alternative mental shortcut:

    • Find largest power of 2 that fits
    • Subtract it, mark that position as 1
    • Repeat with remainder
    • Fill remaining positions with 0

    Decimal Fractions to Binary

    Converting decimal fractions (numbers with decimal points) to binary uses a different method: multiply by 2.

    Multiply by 2 Method (For Fractions)

    Algorithm:

    1. Take the fractional part only
    2. Multiply by 2
    3. If result >= 1, record 1 and subtract 1; if result < 1, record 0
    4. Take new fractional part
    5. Repeat until fraction becomes 0 (or desired precision)

    Example 1: Convert 0.25 to Binary

    Step-by-step:

    StepFractionx 2Integer PartNew Fraction
    10.250.500.5
    20.51.010.0

    Read integer parts top to bottom: 0.01

    Verification:

    • 0.01 in binary = (0 x 21) + (1 x 22)
    • = 0 x 0.5 + 1 x 0.25 = 0.25

    Example 2: Convert 0.75 to Binary

    Step-by-step:

    StepFractionx 2Integer PartNew Fraction
    10.751.510.5
    20.51.010.0

    Result: 0.11

    Verification:

    • 0.11 = (1 x 0.5) + (1 x 0.25) = 0.5 + 0.25 = 0.75

    Example 3: Convert 0.625 to Binary

    Step-by-step:

    StepFractionx 2Integer PartNew Fraction
    10.6251.2510.25
    20.250.500.5
    30.51.010.0

    Result: 0.101

    Verification:

    • 0.101 = (1 x 0.5) + (0 x 0.25) + (1 x 0.125)
    • = 0.5 + 0 + 0.125 = 0.625

    Example 4: Repeating Binary Fraction

    Convert 0.1 (decimal) to binary:

    StepFractionx 2Integer PartNew Fraction
    10.10.200.2
    20.20.400.4
    30.40.800.8
    40.81.610.6
    50.61.210.2
    60.20.400.4 (cycle repeats)

    Result: 0.0001100110011... (repeating)

    Key insight: Many decimal fractions that terminate (like 0.1) become infinitely repeating in binary. This is why computers can't represent 0.1 exactly.

    Combining Integer and Fractional Parts

    Example: Convert 13.25 to binary

    Step 1: Convert integer part (13)

    • 13 -> 1101 (as shown earlier)

    Step 2: Convert fractional part (0.25)

    • 0.25 -> 0.01 (as shown earlier)

    Step 3: Combine with decimal point

    • Result: 1101.01

    Negative Numbers in Binary

    There are several ways to represent negative numbers in binary. The most common method in computing is two's complement.

    Sign-Magnitude Representation

    Simple approach: Use leftmost bit for sign

    • 0 = positive, 1 = negative
    • Remaining bits represent magnitude

    Example: 8-bit representation

    • +5 = 00000101
    • -5 = 10000101

    Drawbacks:

    • Two representations of zero (+0 and -0)
    • Addition/subtraction require different logic
    • Rarely used in modern computers

    Two's Complement (Standard Method)

    Two's complement is the standard way computers represent signed integers. It allows using the same circuitry for addition and subtraction.

    How to convert negative decimal to two's complement:

    Method 1 (Definition):

    1. Convert absolute value to binary
    2. Invert all bits (0->1, 1->0)
    3. Add 1 to the result

    Method 2 (Alternative):

    1. Convert absolute value to binary
    2. Starting from right, keep bits same until first 1 (inclusive)
    3. Invert all remaining bits to the left

    Example: Convert -5 to 8-bit Two's Complement

    Method 1:

    Step 1: Convert 5 to binary (8-bit)

    • 5 = 00000101

    Step 2: Invert all bits

    • 11111010

    Step 3: Add 1

    • 11111010 + 1 = 11111011

    Result: -5 in 8-bit two's complement = 11111011

    Method 2 (same result):

    • 5 = 00000101
    • Keep rightmost bits up to and including first 1: ...101
    • Invert remaining left bits: 11111011

    Why Two's Complement Works

    Key properties:

    • MSB (leftmost bit) indicates sign (0 = positive, 1 = negative)
    • Only one representation of zero
    • Addition and subtraction use same circuit
    • Range for n bits: -2^(n-1) to 2^(n-1) - 1

    Example: 8-bit range

    • Minimum: -128 (10000000)
    • Maximum: +127 (01111111)
    • Total: 256 values (28)

    Two's Complement Conversion Table

    Decimal8-bit Two's ComplementNotes
    000000000Only one zero
    100000001Positive
    12701111111Maximum positive
    -111111111All 1s
    -211111110
    -12710000001
    -12810000000Minimum (special case)

    Important Note on Bit Width

    Two's complement requires a fixed bit width (8-bit, 16-bit, 32-bit, etc.). The same binary pattern means different things with different bit widths:

    • 8-bit: 11111111 = -1
    • 16-bit: 0000000011111111 = +255
    • Without knowing bit width, interpretation is ambiguous

    Binary Place Values and Bit Length

    Understanding place values helps you read and construct binary numbers.

    Binary Place Values (Powers of 2)

    Each position in a binary number represents a power of 2:

    Position76543210
    Power of 22726252423222120
    Decimal value1286432168421

    Example: Reading 10110101

    Position76543210
    Binary10110101
    Value128032160401

    Total: 128 + 32 + 16 + 4 + 1 = 181

    Fractional Place Values (Negative Powers of 2)

    Positions right of the decimal point represent negative powers of 2:

    Position-1-2-3-4
    Power of 221222324
    Decimal value0.50.250.1250.0625
    Fraction1/21/41/81/16

    Example: Reading 0.1011

    • 0.1011 = (1 x 0.5) + (0 x 0.25) + (1 x 0.125) + (1 x 0.0625)
    • = 0.5 + 0 + 0.125 + 0.0625 = 0.6875

    How Many Bits Do I Need?

    For unsigned (positive) integers:

    The number of bits needed is: log2(n+1) (ceiling of log base 2)

    Or more intuitively:

    Decimal RangeBits NeededMaximum Value
    0-11 bit1 (21 - 1)
    0-32 bits3 (22 - 1)
    0-73 bits7 (23 - 1)
    0-154 bits15 (24 - 1)
    0-315 bits31 (25 - 1)
    0-636 bits63 (26 - 1)
    0-1277 bits127 (27 - 1)
    0-2558 bits255 (28 - 1)
    0-65,53516 bits65,535 (216 - 1)
    0-4,294,967,29532 bits~4.3 billion

    For signed integers (two's complement):

    Decimal RangeBits NeededRange
    -1 to 01 bit-1 to 0
    -2 to 12 bits-2 to 1
    -8 to 74 bits-8 to 7
    -128 to 1278 bits-128 to 127
    -32,768 to 32,76716 bits+/-32K
    -2,147,483,648 to 2,147,483,64732 bits+/-2.1B

    Rule of thumb: For a number n, you need at least the bit length of its binary representation.

    Decimal to Binary Conversion Table

    Quick reference for common decimal to binary conversions:

    Powers of 2 (Common Values)

    DecimalBinaryNote
    00Zero
    1120
    21021
    410022
    8100023
    161000024
    3210000025
    64100000026
    1281000000027
    25610000000028
    512100000000029
    102410000000000210 (1 KB)

    0-32 Conversion Table

    DecimalBinaryDecimalBinary
    001710001
    111810010
    2101910011
    3112010100
    41002110101
    51012210110
    61102310111
    71112411000
    810002511001
    910012611010
    1010102711011
    1110112811100
    1211002911101
    1311013011110
    1411103111111
    15111132100000
    1610000

    Common Byte Values

    DecimalBinaryHexadecimal
    127011111117F
    1281000000080
    25511111111FF

    Common Use Cases

    Understanding where binary conversion is used helps contextualize its importance.

    Programming and Computer Science

    Bit flags and masks:

    • Store multiple boolean values in one integer
    • Example: File permissions (read=4, write=2, execute=1)
    • 7 in binary (111) = read + write + execute

    Bitwise operations:

    • AND, OR, XOR, NOT operations on binary
    • Used for encryption, compression, graphics
    • Example: 1010 AND 1100 = 1000

    Low-level programming:

    • Assembly language uses binary directly
    • Device drivers manipulate bits
    • Embedded systems work with registers

    Networking and IP Addresses

    IP addresses:

    • IPv4 addresses are 32-bit binary numbers
    • Example: 192.168.1.1 = 11000000.10101000.00000001.00000001

    Subnet masks:

    • Define network and host portions
    • Example: 255.255.255.0 = 11111111.11111111.11111111.00000000

    MAC addresses:

    • 48-bit hardware addresses
    • Represented in hexadecimal, stored in binary

    Data Storage and Encoding

    Character encoding:

    • ASCII uses 7 or 8 bits per character
    • Unicode uses variable-length binary
    • 'A' = 65 decimal = 01000001 binary

    Color representation:

    • RGB colors use 8 bits per channel
    • Example: Red (255, 0, 0) = 11111111, 00000000, 00000000

    File sizes:

    • Kilobyte (KB) = 1024 bytes (210)
    • Megabyte (MB) = 1024 KB (220)
    • Binary multiples vs. decimal multiples

    Digital Electronics

    Logic gates:

    • AND, OR, NOT gates process binary signals
    • Foundation of all digital circuits
    • CPU operations built from logic gates

    Memory addressing:

    • RAM addresses in binary
    • 16-bit address = 216 = 65,536 locations

    Developer Examples

    Programming languages provide built-in functions for decimal to binary conversion.

    Python

    Using bin() function:

    # Convert decimal to binary
    number = 13
    binary = bin(number)
    print(binary)  # Output: 0b1101
    
    # Remove '0b' prefix
    binary_without_prefix = bin(number)[2:]
    print(binary_without_prefix)  # Output: 1101
    
    # More examples
    print(bin(25))   # 0b11001
    print(bin(255))  # 0b11111111
    print(bin(-5))   # -0b101 (negative sign, not two's complement)

    Custom padding to fixed width:

    # Pad to 8 bits
    number = 13
    binary_8bit = format(number, '08b')
    print(binary_8bit)  # Output: 00001101
    
    # Pad to 16 bits
    binary_16bit = format(number, '016b')
    print(binary_16bit)  # Output: 0000000000001101

    Two's complement for negative numbers:

    # Two's complement (8-bit)
    def to_twos_complement(n, bits=8):
        if n >= 0:
            return format(n, f'0{bits}b')
        else:
            return format((1 << bits) + n, f'0{bits}b')
    
    print(to_twos_complement(-5, 8))  # 11111011
    print(to_twos_complement(5, 8))   # 00000101

    JavaScript

    Using toString(2) method:

    // Convert decimal to binary
    let number = 13;
    let binary = number.toString(2);
    console.log(binary);  // Output: 1101
    
    // More examples
    console.log((25).toString(2));   // 11001
    console.log((255).toString(2));  // 11111111
    console.log((-5).toString(2));   // -101 (keeps negative sign)

    Padding to fixed width:

    // Pad to 8 bits
    let number = 13;
    let binary8bit = number.toString(2).padStart(8, '0');
    console.log(binary8bit);  // 00001101
    
    // Pad to 16 bits
    let binary16bit = number.toString(2).padStart(16, '0');
    console.log(binary16bit);  // 0000000000001101

    Two's complement workaround:

    // Two's complement for negative (8-bit)
    function toTwosComplement(n, bits = 8) {
        if (n >= 0) {
            return n.toString(2).padStart(bits, '0');
        } else {
            return ((1 << bits) + n).toString(2);
        }
    }
    
    console.log(toTwosComplement(-5, 8));  // 11111011
    console.log(toTwosComplement(5, 8));   // 00000101

    Important JavaScript note: The toString() method works with radix 2-36. For negative numbers, it uses a minus sign, not two's complement.

    Safe integer limits:

    // JavaScript safe integer range
    console.log(Number.MAX_SAFE_INTEGER);  // 9007199254740991 (2^53 - 1)
    console.log(Number.MIN_SAFE_INTEGER);  // -9007199254740991
    
    // For larger numbers, use BigInt
    let bigNumber = 9007199254740992n;  // Note the 'n' suffix
    console.log(bigNumber.toString(2));  // Works with BigInt

    Other Languages

    C/C++:

    // Using bitset (C++)
    #include <bitset>
    std::bitset<8> binary(13);
    std::cout << binary;  // 00001101

    Java:

    // Integer.toBinaryString()
    int number = 13;
    String binary = Integer.toBinaryString(number);
    System.out.println(binary);  // 1101

    Why Some Decimals Can't Be Represented Exactly in Binary

    This is one of the most common sources of confusion in computing.

    The Fundamental Problem

    Decimal fractions that terminate nicely (like 0.1, 0.2, 0.3) often become infinitely repeating in binary.

    Why this happens:

    • Decimal uses powers of 10 (10, 100, 1000...)
    • Binary uses powers of 2 (2, 4, 8, 16...)
    • Fractions like 1/10 can be expressed exactly in decimal (0.1)
    • But 1/10 cannot be expressed exactly as a sum of powers of 2

    Example: Why 0.1 Repeats in Binary

    0.1 in binary = 0.00011001100110011... (repeating)

    Attempting to represent it:

    Binary FractionDecimal ValueRemaining
    0.000.1
    0.0000.1
    0.00000.1
    0.00010.06250.0375
    0.000110.093750.00625
    0.0001100.093750.00625
    0.00011000.093750.00625
    0.000110010.097656250.00234375

    The pattern 1100 repeats infinitely. You can never get exactly 0.1.

    Which Decimal Fractions Convert Exactly?

    Rule: A decimal fraction converts exactly to binary if and only if it can be expressed as:

    n / 2^k where n and k are integers

    Examples that convert exactly:

    • 0.5 = 1/2 = 0.1 (binary)
    • 0.25 = 1/4 = 0.01 (binary)
    • 0.125 = 1/8 = 0.001 (binary)
    • 0.625 = 5/8 = 0.101 (binary)
    • 0.75 = 3/4 = 0.11 (binary)

    Examples that don't convert exactly:

    • 0.1 = 1/10 (10 = 2 x 5, has factor 5)
    • 0.2 = 1/5 (has factor 5)
    • 0.3 = 3/10 (has factor 5)
    • 0.6 = 3/5 (has factor 5)

    IEEE 754 Floating-Point Representation

    Computers store decimal numbers using IEEE 754 standard:

    32-bit (float): 1 sign bit + 8 exponent bits + 23 mantissa bits 64-bit (double): 1 sign bit + 11 exponent bits + 52 mantissa bits

    This means:

    • Limited precision (not infinite)
    • Numbers are rounded to nearest representable value
    • 0.1 is approximated, not exact

    Consequences:

    # Python example
    0.1 + 0.2  # Returns 0.30000000000000004, not 0.3
    
    # Why?
    # 0.1 rounded to nearest binary
    # 0.2 rounded to nearest binary  
    # Sum produces slight error

    Best practices:

    • Avoid equality tests on floating-point (use tolerance)
    • Use decimal libraries for money/finance
    • Understand rounding can accumulate

    Troubleshooting Common Issues

    "I entered a decimal fraction and got a long/repeating result"

    Problem: Decimal fractions like 0.1 create long or infinite binary representations.

    Why it happens:

    • Not all decimal fractions have exact binary equivalents
    • 0.1, 0.2, 0.3, etc. repeat infinitely in binary
    • Converters may show truncated or rounded results

    Example:

    • Input: 0.1
    • Exact binary: 0.0001100110011... (repeating)
    • Truncated to 20 bits: 0.00011001100110011001

    Solution:

    • This is mathematically correct
    • For exact representation, stick to fractions like 0.5, 0.25, 0.125
    • Or use decimal-based number systems for finance

    "My result is longer/shorter than expected"

    Problem: Binary result has more or fewer digits than anticipated.

    Causes:

    No leading zeros:

    • Binary doesn't show unnecessary leading zeros
    • 5 = 101 (not 00000101)
    • To see fixed-width, specify bit length

    Different bit widths:

    • 8-bit: 00001101
    • 16-bit: 0000000000001101
    • Without specified width, minimal representation shown

    Solution:

    • Understand that 1101 and 00001101 are the same value
    • Specify bit width if you need fixed format
    • Use padding in code (as shown in developer examples)

    "Large number doesn't match JavaScript result"

    Problem: Very large numbers produce unexpected results in JavaScript.

    Why it happens:

    • JavaScript uses IEEE 754 double-precision
    • Safe integer range: -(253 - 1) to (253 - 1)
    • Numbers beyond this lose precision

    Example:

    // Loses precision
    let large = 9007199254740993;
    console.log(large);  // 9007199254740992 (wrong!)
    
    // Binary conversion affected
    console.log(large.toString(2));  // Incorrect binary

    Solution:

    • Use BigInt for large integers
    • Add 'n' suffix: 9007199254740993n
    • BigInt supports toString(2)

    Safe vs Unsafe:

    • Safe: 9007199254740991 (253 - 1)
    • Unsafe: 9007199254740992+ (precision lost)

    "Negative number doesn't match two's complement calculator"

    Problem: Your negative binary doesn't match another calculator's two's complement result.

    Why it happens:

    Different representations:

    • Sign-magnitude: -1010 (minus sign + magnitude)
    • Two's complement: 10110 (8-bit example)
    • Different tools use different formats

    Bit width matters:

    • -5 in 8-bit: 11111011
    • -5 in 16-bit: 1111111111111011
    • Same value, different representation

    Python/JavaScript behavior:

    • bin(-5) produces "-0b101" (sign-magnitude)
    • Not two's complement
    • Need custom function for two's complement

    Solution:

    • Verify which format you need
    • Specify bit width for two's complement
    • Use appropriate conversion method

    "Result has 0b prefix"

    Problem: Binary result shows "0b" prefix.

    Why it happens:

    • Python's bin() function adds "0b" prefix
    • Indicates binary literal in code
    • Standard programming notation

    Solution:

    • Remove prefix: bin(n)[2:]
    • Or keep it if using in code
    • Just cosmetic difference

    Prefix conventions:

    • Binary: 0b (e.g., 0b1101)
    • Hexadecimal: 0x (e.g., 0xD)
    • Octal: 0o (e.g., 0o15)

    Frequently Asked Questions

    1. How do you convert a decimal number to binary?

    To convert a decimal integer to binary, use the division by 2 method:

    Step-by-step process:

    1. Divide the decimal number by 2
    2. Record the quotient and remainder (0 or 1)
    3. Divide the quotient by 2
    4. Repeat until quotient becomes 0
    5. Read all remainders from bottom to top

    Example: Convert 13 to binary

    • 13 / 2 = 6 remainder 1
    • 6 / 2 = 3 remainder 0
    • 3 / 2 = 1 remainder 1
    • 1 / 2 = 0 remainder 1

    Reading remainders bottom to top: 1101

    Verification: 1101 = 8 + 4 + 0 + 1 = 13

    Why this works: Each division extracts one binary digit (bit). The remainder tells you whether that power of 2 is present (1) or absent (0) in the binary representation.

    2. What is the fastest way to convert decimal to binary by hand?

    The fastest manual method depends on your comfort with powers of 2:

    Method 1: Division by 2 (Most systematic)

    • Best for accuracy
    • Works for any size number
    • As described in FAQ 1

    Method 2: Powers of 2 subtraction (Fastest if you know powers)

    Steps:

    1. Find the largest power of 2 that fits in your number
    2. Mark that bit position as 1
    3. Subtract that power from your number
    4. Repeat with the remainder
    5. Mark unused positions as 0

    Example: Convert 45 to binary

    Powers of 2: 32, 16, 8, 4, 2, 1

    • 45 - 32 = 13 (mark position 5: 100000)
    • 13 - 8 = 5 (mark position 3: 101000)
    • 5 - 4 = 1 (mark position 2: 101100)
    • 1 - 1 = 0 (mark position 0: 101101)

    Result: 101101

    Quick mental tricks:

    • Memorize powers of 2 up to 1024
    • Recognize patterns (255 = 11111111, all 1s)
    • Use halving: each bit represents half the previous

    Fastest for small numbers: Just memorize 0-15!

    3. What do MSB and LSB mean?

    MSB (Most Significant Bit):

    • Leftmost bit in a binary number
    • Represents the largest power of 2
    • Has the greatest impact on the number's value
    • In signed numbers, often indicates the sign

    LSB (Least Significant Bit):

    • Rightmost bit in a binary number
    • Represents 20 (value of 1)
    • Has the smallest impact on the number's value
    • Determines if number is odd (1) or even (0)

    Example: In binary number 10110101

      1    0    1    1    0    1    0    1
                                        
     MSB                                LSB
    (128)                               (1)

    Why it matters:

    MSB significance:

    • Changing MSB changes value by +/-128 (in 8-bit)
    • In two's complement, MSB = sign bit
    • MSB-first transmission (big-endian)

    LSB significance:

    • Changing LSB changes value by +/-1
    • Determines odd/even parity
    • LSB-first transmission (little-endian)

    Practical use:

    • Bit shifting operations
    • Data transmission order
    • Priority in rounding

    4. How do you convert a decimal fraction (like 0.25) to binary?

    To convert the fractional part of a decimal to binary, use the multiply by 2 method:

    Step-by-step process:

    1. Take only the fractional part (digits after decimal point)
    2. Multiply by 2
    3. If result >= 1, record 1 and subtract 1 from result; if < 1, record 0
    4. Take the new fractional part
    5. Repeat steps 2-4 until fraction becomes 0 (or desired precision)
    6. Read recorded digits from top to bottom

    Example: Convert 0.25 to binary

    • 0.25 x 2 = 0.5 -> record 0, fractional part is 0.5
    • 0.5 x 2 = 1.0 -> record 1, fractional part is 0.0 (done)

    Result: 0.01

    Verification: 0.01 = 0 x (1/2) + 1 x (1/4) = 0.25

    Another example: Convert 0.625 to binary

    • 0.625 x 2 = 1.25 -> record 1, new fraction 0.25
    • 0.25 x 2 = 0.5 -> record 0, new fraction 0.5
    • 0.5 x 2 = 1.0 -> record 1, new fraction 0.0 (done)

    Result: 0.101

    Verification: 0.101 = (1/2) + (1/8) = 0.5 + 0.125 = 0.625

    For mixed numbers (integer + fraction):

    • Convert integer part using division by 2
    • Convert fractional part using multiply by 2
    • Combine with decimal point: integer.fraction

    Example: 13.25 -> 1101.01

    5. Why can't 0.1 be represented exactly in binary?

    0.1 cannot be represented exactly in binary because it creates an infinitely repeating pattern.

    The mathematical reason:

    Binary fractions can only represent values that are sums of negative powers of 2:

    • 1/2 = 0.5
    • 1/4 = 0.25
    • 1/8 = 0.125
    • 1/16 = 0.0625
    • etc.

    0.1 = 1/10:

    • 10 = 2 x 5
    • Has factor of 5 (not a power of 2)
    • Cannot be expressed as sum of powers of 2 exactly

    What happens:

    Converting 0.1 to binary:

    • 0.1 x 2 = 0.2 -> 0
    • 0.2 x 2 = 0.4 -> 0
    • 0.4 x 2 = 0.8 -> 0
    • 0.8 x 2 = 1.6 -> 1
    • 0.6 x 2 = 1.2 -> 1
    • 0.2 x 2 = 0.4 -> 0 (cycle repeats)

    Result: 0.0001100110011... (pattern "1100" repeats forever)

    Analogy: Just like 1/3 can't be represented exactly in decimal (0.333...), some fractions can't be represented exactly in binary.

    Consequences in computing:

    • Computers use finite precision (IEEE 754)
    • 0.1 gets rounded to nearest representable value
    • Small errors accumulate: 0.1 + 0.2 != 0.3 exactly

    What converts exactly:

    • Fractions like 0.5, 0.25, 0.125, 0.625 (powers of 2 denominators)
    • NOT fractions like 0.1, 0.2, 0.3, 0.7 (have non-2 factors)

    6. Does this tool support negative numbers? What format is used?

    Yes, this tool supports negative numbers.

    Format options depend on the implementation:

    Option 1: Sign-magnitude (most common for general converters)

    • Uses minus sign prefix
    • Example: -13 -> -1101
    • Simple and intuitive
    • Not how computers store negatives internally

    Option 2: Two's complement (computer science standard)

    • Fixed-bit-width representation
    • Example: -13 in 8-bit -> 11110011
    • How computers actually store negative integers
    • Requires specifying bit width

    Most online converters (including typical implementations) use sign-magnitude for simplicity:

    • Input: -25
    • Output: -11001 (minus sign plus magnitude)

    For two's complement output:

    • Typically requires selecting bit width (8, 16, 32, 64)
    • Some tools have a checkbox or dropdown
    • More appropriate for low-level programming contexts

    Check your specific tool to confirm which format it uses.

    7. What is two's complement and when do I need it?

    Two's complement is the standard method computers use to represent signed (positive and negative) integers in binary.

    How it works:

    • Uses a fixed number of bits (8, 16, 32, 64, etc.)
    • MSB (leftmost bit) indicates sign: 0 = positive, 1 = negative
    • Positive numbers: standard binary
    • Negative numbers: invert all bits and add 1

    Why computers use it:

    • Only one representation of zero
    • Addition and subtraction use the same circuit
    • Extends naturally to all bit widths
    • Efficient in hardware

    When you need two's complement:

    Low-level programming:

    • Assembly language
    • Bit manipulation
    • Device drivers
    • Embedded systems

    Computer architecture:

    • Understanding how CPUs work
    • Memory representation
    • Register operations

    Networking:

    • Some protocols use two's complement
    • Binary data structures

    You DON'T need it for:

    • General decimal-to-binary conversions
    • Learning binary number system
    • Basic math in binary
    • Most high-level programming

    Example: -5 in 8-bit two's complement

    Method:

    1. 5 in binary: 00000101
    2. Invert bits: 11111010
    3. Add 1: 11111011

    Result: -5 = 11111011

    Verification: 11111011 + 00000101 = 100000000 (overflow discarded) = 00000000 = 0

    8. What does the 0b prefix mean in binary numbers?

    The 0b prefix (or 0B) is a notation used in programming to indicate a binary literal.

    Purpose: Tells the compiler/interpreter that the following digits are binary (base 2), not decimal.

    Examples:

    binary_num = 0b1101  # This is 13 in decimal
    another = 0b11001    # This is 25 in decimal

    Without the prefix: The number would be interpreted as decimal

    wrong = 1101  # This is one thousand one hundred one (decimal), not 13!

    Language support:

    Python:

    print(0b1101)  # Output: 13
    print(bin(13))  # Output: 0b1101

    JavaScript (ES6+):

    let binary = 0b1101;  // 13
    console.log(binary);  // 13

    C/C++ (C++14+):

    int binary = 0b1101;  // 13

    Java (Java 7+):

    int binary = 0b1101;  // 13

    Other prefixes in programming:

    • 0x or 0X: Hexadecimal (base 16)
    • Example: 0x1A = 26 decimal
    • 0o or 0O: Octal (base 8)
    • Example: 0o17 = 15 decimal
    • No prefix: Decimal (base 10)
    • Example: 13 = 13 decimal

    When you see 0b: The number is written in binary notation for clarity in code.

    Removing the prefix: Many tools show 0b in output. To get just the binary digits, remove the first two characters.

    9. How many bits do I need to represent my number?

    The number of bits needed depends on whether your number is positive only or includes negative numbers.

    For positive integers (unsigned):

    Formula: Bits needed = log2(n + 1)

    Or more simply: Find the length of the binary representation

    Quick reference:

    Number RangeBits Needed
    0 to 11 bit
    0 to 32 bits
    0 to 73 bits
    0 to 154 bits
    0 to 315 bits
    0 to 636 bits
    0 to 1277 bits
    0 to 2558 bits
    0 to 65,53516 bits
    0 to 4,294,967,29532 bits

    Rule: For number n, count the binary digits

    • 13 -> 1101 -> 4 bits minimum
    • 255 -> 11111111 -> 8 bits
    • 1000 -> 1111101000 -> 10 bits

    For signed integers (with negatives):

    You need one extra bit for the sign.

    Common sizes:

    • 8-bit signed: -128 to +127
    • 16-bit signed: -32,768 to +32,767
    • 32-bit signed: -2,147,483,648 to +2,147,483,647
    • 64-bit signed: -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807

    Examples:

    • Number 13: needs 4 bits unsigned, or 8 bits signed (typical)
    • Number 200: needs 8 bits unsigned, or 16 bits signed (typical)
    • Number -13: needs at least 8 bits (using two's complement)

    Practical choices: Use standard sizes (8, 16, 32, 64 bits) even if you need fewer.

    10. How do I convert binary back to decimal?

    To convert binary to decimal, multiply each bit by its place value (power of 2) and sum the results.

    Step-by-step method:

    1. Write the binary number
    2. Number positions from right to left, starting at 0
    3. For each bit that is 1, calculate 2^(position)
    4. Add all these values

    Example: Convert 1101 to decimal

    Binary:    1    1    0    1
    Position:  3    2    1    0
    Value:     8    4    2    1

    Calculation:

    • Position 3: 1 x 23 = 1 x 8 = 8
    • Position 2: 1 x 22 = 1 x 4 = 4
    • Position 1: 0 x 21 = 0 x 2 = 0
    • Position 0: 1 x 20 = 1 x 1 = 1

    Sum: 8 + 4 + 0 + 1 = 13

    Quick method: Use place values

    128  64  32  16   8   4   2   1
      1   0   1   1   0   1   0   1
    
    128 + 32 + 16 + 4 + 1 = 181

    For binary fractions:

    Use negative powers of 2 for digits right of decimal point.

    Example: 0.101 to decimal

    Position:   -1    -2    -3
    Power:      21   22   23
    Value:      0.5   0.25  0.125
    Binary:      1     0     1

    Calculation: (1 x 0.5) + (0 x 0.25) + (1 x 0.125) = 0.5 + 0 + 0.125 = 0.625

    For mixed numbers:

    • 1101.101 = 13.625
    • Convert integer part: 1101 = 13
    • Convert fractional part: 0.101 = 0.625
    • Combine: 13 + 0.625 = 13.625

    Use our Binary to Decimal Converter for instant results!

    12. Why does JavaScript's result differ for large numbers?

    JavaScript loses precision with integers beyond a certain size due to its number representation.

    The problem:

    JavaScript uses IEEE 754 double-precision floating-point for all numbers (until BigInt was introduced).

    Safe integer range:

    • Minimum: -(253 - 1) = -9,007,199,254,740,991
    • Maximum: +(253 - 1) = +9,007,199,254,740,991

    Beyond this range, integers lose precision:

    // Precision lost
    console.log(9007199254740992);      // 9007199254740992
    console.log(9007199254740993);      // 9007199254740992 (wrong!)
    console.log(9007199254740993 + 1);  // 9007199254740994 (skipped!)
    
    // Binary conversion affected
    console.log((9007199254740993).toString(2));
    // Result will be wrong due to precision loss

    Why this happens:

    IEEE 754 double precision:

    • 1 sign bit
    • 11 exponent bits
    • 52 mantissa bits
    • Can only represent 253 distinct integers exactly

    Above 253: Numbers are spaced further apart

    • Can represent 253, but not 253 + 1
    • Can represent 253 + 2, but not 253 + 3
    • Gaps increase as numbers get larger

    Solution: Use BigInt:

    // BigInt for large integers (ES2020+)
    let large = 9007199254740993n;  // Note the 'n' suffix
    console.log(large);  // 9007199254740993n (correct!)
    
    // Binary conversion works
    console.log(large.toString(2));
    // Correct binary representation
    
    // Arithmetic works
    console.log(large + 1n);  // 9007199254740994n (correct!)

    Checking for safe integers:

    Number.isSafeInteger(9007199254740991);  // true
    Number.isSafeInteger(9007199254740992);  // false
    
    Number.MAX_SAFE_INTEGER;  // 9007199254740991
    Number.MIN_SAFE_INTEGER;  // -9007199254740991

    Important notes:

    • BigInt cannot mix with regular numbers in operations
    • BigInt doesn't work with Math methods
    • BigInt has full precision for any size integer
    • Use BigInt when working with large IDs, timestamps, or precise calculations
    Tool Point

    Free tools for everyday tasks, from quick text fixes to image edits, SEO checks, and calculators. No sign-up needed. Fast, private, and easy to use.

    © 2026 Tool Point. All rights reserved.