[Math] How to find bits you need to represent one variable? How many integers( 16 or 32 bits) you need when programming the problem

computer science

Question:
Use binary coded GA(Genetic algorithms), your problem is to find vector with real numbers $\in [0,5]$ and you want your answer at least to three decimal places(0.001).

a) How many bits you need to represent one variable

b) the dimension of your problem is 10 or you optimize ten variables. How many integers( 16 or 32 bits) you need when programming the problem, in case you use bit-fields, in which you have reserved for each variable the bits it exactly needs?

Best Answer

Since the problem is still open, let me take a shot at it.

For one variable, if you store the integer part separately and the decimal part separately, you need $3$ bits for real numbers $\in [0,5]$ and the decimal part could be $0.001$ upto $0.999$ (since your condition was three decimal places). Which means the decimal part storage needs $$\left\lceil log_2 \hspace{4pt}999 \right\rceil = 10 $$

Therefore for a single variable you need $3$ bits for real part and $10$ bits for decimal part.

For part b, if you are optimizing $10$ variables, it depends if what kind of arithmetic or computation you have with those variables. If multiplication and exponents are also involved, you have to know the bounds of those computation, then one can make a reasonable justification.