0
$\begingroup$

I would like to convert 0,347 and 0,9828 to binary, how can I do that?

I know that sucessive multiplication by 2 can do this, but this method seems very painful and even ineffective since the size of count.

This is for a question, and I think that sucessive multiplication is needed. But, in 0,347, I did more than 20 multiplication and did not reach result. Is this normal?

$\endgroup$
  • $\begingroup$ In what setting are you converting the representations in? In program code? By hand? Somewhere else? $\endgroup$ – dkaeae Apr 9 at 9:48
  • $\begingroup$ You are not converting “float to binary”, you are converting a textual representation to a floating point number. $\endgroup$ – gnasher729 Apr 9 at 12:57
  • $\begingroup$ @dkaeae By hand $\endgroup$ – Mycroft Apr 9 at 14:05
1
$\begingroup$

If I understand your question correctly, you want to determine the binary representation of a floating-point number by hand. I assume you are talking about the IEEE 754 floating-point format, since this is the most common format.

You can indeed do this by successively multiplying with 2. However, just multiplying does not result in anything useful, you should also subtract one (1) every time the intermediate result is greater than or equal to 1. To understand this, you must understand how floating-point numbers are stored. This is explained pretty well on Wikipedia (and probably many other sources), including the algorithm you mean (see here).

To do this by hand is quite painful indeed. It's normal that you have to do more than 20 multiplications. You first need a few multiplications to normalize the number and determine the exponent (i.e. scale the number such that it has the form 1.xxxxx * 2^exponent). After that, each multiplication yields exactly one bit of the mantissa. A single-precision floating-point number has a 23-bit mantissa, so to convert the number 0.347 to single-precision floating-point, you need to do 25 multiplications. A double-precision floating-point has a 52-bit mantissa, so you'll need 54 multiplications!

NB: For sake of simplicity, I did not take into account numbers larger than 1, negative numbers, special numbers (such as NaN, +/- infinity, denormal numbers, etc.) and other aspects such as rounding. These seem out of the scope of your question.

$\endgroup$
0
$\begingroup$

First you look at the position of the decimal sign and a possible exponent, and you find that the result you want is “347” divided by $10^3$ and “9828” divided by $10^4$.

You convert “347” and “9828” to floating point - there is no multiplication by 2 involved, but multiplication by 10. You probably get the power of 10 by looking up a table.

Doing this with high precision is harder.

$\endgroup$
  • $\begingroup$ This is for a question, and I think that sucessive multiplication is needed. But, in 0,347, I did more than 20 multiplication and did not reach result. Is this normal? $\endgroup$ – Mycroft Apr 9 at 14:09
  • $\begingroup$ I don’t know what you are multiplying, but I’d multiply x = 3*10+4, y = x*10+7. Then divide 347 /1000. Using a computer, not by hand. $\endgroup$ – gnasher729 Apr 9 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.