Binary to Decimal Conversion
Let’s first understand, how to convert binary to decimal with examples.
Input: 1011 (Binary)
Output: 11 (Decimal)
Explanation:
To illustrate, let’s convert the binary number 1011
to decimal:
- Binary:
1011
- Calculation:
- 1×23+0×22+1×21+1×201×23+0×22+1×21+1×20
- 1×8+0×4+1×2+1×11×8+0×4+1×2+1×1
- 8+0+2+1=118+0+2+1=11
- Decimal:
11
How to convert binary to decimal in JavaScript?
A binary number is a number expressed in the binary numeral system, which uses only two symbols 0 and 1. Decimal numbers are base 10 in a JavaScript number system that uses 10 digits from 0 to 9. We are given a number as Binary input we have to convert it into decimal in JavaScript and print the result.