Computer Science, asked by dharshinia150, 1 month ago

fractional decimal number to binary conversion 1) . convert (42.64) to binary​

Answers

Answered by babydoll321
5

Given a fraction decimal number n and integer k, convert decimal number n into equivalent binary number up-to k precision after decimal point.

Examples:

Input: n = 2.47, k = 5

Output: 10.01111

Input: n = 6.986 k = 8

Output: 110.11111100

We strongly recommend that you click here and practice it, before moving on to the solution.

A) Convert the integral part of decimal to binary equivalent

Divide the decimal number by 2 and store remainders in array.

Divide the quotient by 2.

Repeat step 2 until we get the quotient equal to zero.

Equivalent binary number would be reverse of all remainders of step 1.

B) Convert the fractional part of decimal to binary equivalent

Multiply the fractional decimal number by 2.

Integral part of resultant decimal number will be first digit of fraction binary number.

Repeat step 1 using only fractional part of decimal number and then step 2.

C) Combine both integral and fractional part of binary number.

Illustration

Similar questions