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

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?

-
There are 5001 possible different values of each variable. What is the smallest $n$ such that $2^n$ is at least 5001? – Henning Makholm Feb 13 '12 at 16:37
$5001<2^{13}$, but what it has to do with the problem a)? Do you mean that you need 13 bits( what is bit?) to represent one variable? – alvoutila Feb 13 '12 at 16:45
Bit is a binary digit. It can store one of 2 values: 0 and 1. By using combinations of 0 & 1, you can represent any number. For instance, 7 in Binary is 0111. en.wikipedia.org/wiki/Bit – Inquest Feb 13 '12 at 16:47
No, this isn't "my problem". Do your own homework. – user5137 May 24 '12 at 16:31

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.