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 × 2^{3}) + (1 × 2^{2}) + (1 × 2^{1}) + (0 × 2^{0}) + (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 × 2^{6}) + (0 × 2^{5}) + (0 × 2^{4}) + (1 × 2^{3}) + (0 × 2^{2}) + (1 × 2^{1}) + (1 × 2^{0}) + (1 × 2^{-1}) = (75.5)_{10}
- (101101.01)_{2} = (1 × 2^{5}) + (0 × 2^{4}) + (1 × 2^{3}) + (1 × 2^{2}) + (0 × 2^{1}) + (1 × 2^{0}) + (0 × 2^{-1}) + (1 × 2^{-2}) = (45.25)_{10}
- (11110.11)_{2} = (1 × 2^{4}) + (1 × 2^{3}) + (1 × 2^{2}) + (1 × 2^{1}) + (0 × 2^{0}) + (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.