JavaScript Fractional Binary to Fractional Decimal Converter
Last Updated: 2022-11-07 20:29:19You may already know how to convert an integer Binary number into a Decimal number, but in this post, I will share with you how to convert a fractional Binary number into a fractional Decimal number.
Example of Fractional Binary to Fractional Decimal Number.
Fractional Binary | Fractional Decimal |
1110.011111 | 14.484375 |
1001011.1 | 75.50 |
101101.01 | 45.25 |
11110.11 | 30.75 |
Rules of converting binary fraction part into the decimal fractional part.
- You need to calculate the fraction part separately.
- You need to calculate from left to right
- you need to find the negative power of the 2
- Finally, find the summation of all products.
learn how to convert an integer decimal number into a binary number.
Some example solutions of Fractional Binray to Fractional Decimal Numbers.
- (1110.011111)2 = (1 × 23) + (1 × 22) + (1 × 21) + (0 × 20) + (0 × 2-1) + (1 × 2-2) + (1 × 2-3) + (1 × 2-4) + (1 × 2-5) + (1 × 2-6) = (14.484375)10
- (1001011.1)2 = (1 × 26) + (0 × 25) + (0 × 24) + (1 × 23) + (0 × 22) + (1 × 21) + (1 × 20) + (1 × 2-1) = (75.5)10
- (101101.01)2 = (1 × 25) + (0 × 24) + (1 × 23) + (1 × 22) + (0 × 21) + (1 × 20) + (0 × 2-1) + (1 × 2-2) = (45.25)10
- (11110.11)2 = (1 × 24) + (1 × 23) + (1 × 22) + (1 × 21) + (0 × 20) + (1 × 2-1) + (1 × 2-2) = (30.75)10
Javascript source code of Fractional Binary to Fractional Decimal Converter
Power = -1;
if (FractionPart != "") {
for (i = 0; i < FractionPart.length; i++) {
DecimalOfFractionPart += Number(FractionPart[i]) * Math.pow(2, Power);
Power--;
}
}
Still you face problems, feel free to contact with me, I will try my best to help you.