{
  "id": 20808890,
  "title": "How to Convert Binary to Decimal (Two Methods, Plus the Code Gotchas)",
  "url": "https://urgent.news/2026/11/19/how-to-convert-binary-to-decimal-two-methods-plus-the-code-gotchas",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-19T21:46:06.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/thecodetranslator_147b60a/how-to-convert-binary-to-decimal-two-methods-plus-the-code-gotchas-2m9p"
  },
  "original_language": "en",
  "account": "Converting binary to decimal is a skill you may learn once and then struggle to remember. Here's the simple breakdown, along with the nuances that can trip you up when coding. The place-value method involves writing down the place values under each binary digit, starting from the rightmost digit: 1, 2, 4, 8, 16, 32, and so on. Ignore the places where the binary digit is 0, and add up the remaining values. For example, with the binary number 101101, the calculation would be 32 + 0 + 8 + 4 + 0 + 1, which equals 45.\n\nAn alternative method is the doubling approach. Starting from the left, double your running total and add the next digit. For 101101, you'd run through the totals 1, 2, 5, 11, 22, and finally 45.\n\nUnderstanding why these methods work comes from recognizing the place values. Doubling is quicker for longer binary numbers, and it's the method most programming languages follow. However, there are a few gotchas to be aware of. For instance, the JavaScript function parseInt(0b101101, 2) returns 0, because it stops at the 'b' indicating binary. To avoid this, strip off the prefix or convert to a Number() afterwards.\n\nYou can only parse up to 2^53 - 1 with parseInt, so larger numbers require BigInt. If you're working with Excel's BIN2DEC, it only handles up to 10 digits and treats the first digit as a sign bit, which can lead to unexpected results.\n\nWhen dealing with fractions, remember that each digit after the binary point represents a shrinking weight: 1/2, 1/4, 1/8, and so on. So, 101.011 converts to 5 + 0.25 + 0.125, which is 5.375.\n\nBinary can also be signed, meaning the same bits can represent two different numbers. For example, 11111011 could be either 251 as an unsigned number or -5 in 8-bit two's complement. In the latter case, the leftmost 1 counts as -128, so the value becomes -128 + 64 + 32 + 16 + 8 + 2 + 1, which equals -5.\n\nCommon mistakes include starting place values at 2 instead of 1, reversing the place values, treating a leading 1 as a minus sign outside signed mode, and typing digits other than 0 or 1. To check your work, you can use my free online converter, which shows every step, handles fractions and signed values up to 64 bits, and runs entirely in your browser.",
  "summary": "Binary to decimal is one of those things you learn once and then half-forget. Here is the short version, plus the parts that actually bite in code. The place-value method Write the place values under each digit, starting from the right: 1, 2, 4, 8, 16, 32. Keep the values under a 1 , ignore the ones under a 0 , and add them up. Take 101101 : Digit 1 0 1 1 0 1 Place value 32 16 8 4 2 1 Digit ×…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}