Logo

dev-resources.site

for different kinds of informations.

How to Convert Binary to Decimal

Published at
9/20/2023
Categories
howto
convert
binary
decimal
Author
harshraj8843
Categories
4 categories in total
howto
open
convert
open
binary
open
decimal
open
Author
12 person written this
harshraj8843
open
How to Convert Binary to Decimal

Converting binary to decimal is a common task in computer programming. Binary is a base-2 number system that uses only two digits, 0 and 1. Decimal, on the other hand, is a base-10 number system that uses ten digits, 0 through 9. Converting binary to decimal involves multiplying each digit of the binary number by its corresponding power of 2 and adding up the results.

Conversion

Here's a step-by-step guide on how to convert binary to decimal:

  1. Choose the binary number you want to convert to decimal.
  2. Write down the powers of 2 from right to left, starting with 202^0 .
  3. Multiply each digit of the binary number by its corresponding power of 2.
  4. Add up the results from step 3 to get the decimal value.

Example

Let's walk through an example to illustrate the process. Suppose we want to convert the binary number 1011 to decimal.

  1. The binary number we want to convert is 1011.
  2. The powers of 2 from right to left are 202^0 , 212^1 , 222^2 , and 232^3
  3. We multiply each digit of the binary number by its corresponding power of 2. The results are: 1×20=11 \times 2^0 = 1 , 1×21=21 \times 2^1 = 2 , 0×22=00 \times 2^2 = 0 , and 1×23=81 \times 2^3 = 8
  4. We add up the results from step 3 to get the decimal value.
1+2+0+8=11 1 + 2 + 0 + 8 = 11

Therefore, the decimal value of the binary number 1011 is 11.

Binary-Decimal Table

Here's a table that shows the decimal values of the first 16 binary numbers:

Binary Decimal
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 10
1011 11
1100 12
1101 13
1110 14
1111 15

Sample Code

This code requires @ilihub/code npm package to run.

import { BinaryToDecimal } from "@ilihub/code";

const binary = "10000000";

const decimal = BinaryToDecimal(binary);
console.log(decimal);

// Output
// 128
Enter fullscreen mode Exit fullscreen mode

References


binary Article's
30 articles in total
Favicon
How to convert binary to decimal
Favicon
Udder Overflow - Binary Writeup CTF - Pwnedcr2024
Favicon
Maximum Possible Number by Binary Concatenation
Favicon
House robber III
Favicon
Representação numérica na computação
Favicon
Working with Different File Modes and File Types in Python
Favicon
Understanding Decimal to Binary Conversions: A Guide
Favicon
Elixir pattern matching - save your time, similar with the way of our thinking
Favicon
What the hell are Binary Numbers?
Favicon
Solving a Leetcode problem daily — Day 4 | Add Binary
Favicon
Bitwise Sorcery: Unlocking the Secrets of Binary Manipulation
Favicon
Understanding Binary Representation and Finding Binary Gaps in Python
Favicon
Binary Il - Convert URLs to Il and Secure it - Redirect It 🚀
Favicon
How to Trade Binary Successfully
Favicon
How to Learn Quotex Trading With a 1 Minute Strategy
Favicon
Minimum Changes To Make Alternating Binary String Ruby
Favicon
Hi, Im new here 🤗
Favicon
Binary Operators in Golang
Favicon
Number representation systems. Binary operations
Favicon
Binary and other numerical systems
Favicon
How to Convert Binary to Hexadecimal
Favicon
How to Convert Binary to Octal
Favicon
How to Convert Binary to ASCII
Favicon
How to Convert Binary to Decimal
Favicon
How to Convert ASCII to Binary
Favicon
What is a Binary Number?
Favicon
Operations with binary numbers!
Favicon
BINARY NUMBERS, What are they, how to convert into decimal, operations with them
Favicon
Binary
Favicon
From Binary to Natural Language: The Transforming Landscape of Programming Languages

Featured ones: