I assume here that you want to use the first crossOverPoint bits of the binary representation of the first double and the last (64-crossOverPoint) bits of the second double. If you use Strings you´ll have to make sure to include leading 0s. Simple logic which we studied in college time to convert a Decimal floating point number to binary is as below:
Convert 18.6875D to binary:
Integral Part = 18D
18/2 => quotient=9 remainder=0
9/2 => quotient=4 remainder=1
4/2 => quotient=2 remainder=0
2/2 => quotient=1 remainder=0
1/2 => quotient=0 remainder=1 (quotient=0 stop)
Hence, 18D = 10010B
Fractional Part = .6875D
.6875*2=1.375 => whole number is 1
.375*2=0.75 => whole number is 0
.75*2=1.5 => whole number is 1
.5*2=1.0 => whole number is 1
Hence .6875D = .1011B
Therefore, 18.6875D = 10010.1011B
The first thing to realize is that the binary representation of 0.15625 is not 0.00101. Yes, that is what you would write if you were writing out the number by hand. The actual representation of the number within the computer using IEE 754 for single precision 32 bit. This is specified as part of the Java Language Specification 4.2:
The floating-point types are float, whose values include the 32-bit IEEE 754 floating-point numbers, and double, whose values include the 64-bit IEEE 754 floating-point numbers.
The IEEE 754 binary representation of 0.15625 is: 0x3E200000 which can be broken down into:
* a sign bit: 0 meaning it is positive.
* the exponent for bits: 01111100 which is 124. This value is subtracted from 127 to get the actual exponent that will be used (-3)
* the significand: .0100000 00000000 00000000. The . I put there is for reading so that it is bytes, not part of the value (the significant uses the lower 23 bits of the number... so the 24th bit I represent with a . so the alignment is easier to read) This value is added to 1 giving us the binary value of 1.010.... or in base 10, 1.25000...
Combining these all together, we get:
(-1)0 * 1.012 * 2-3 which comes out to be, when written, 0.00101. But remember, that we´re really dealing with 0x3E200000.
To convert float to binary we can use the following techniques in Java:
long bits = Double.doubleToLongBits(18.6875);
I am not familiar with Genetic algorithm, but got few references which may help you.
Genetic.java - Click Here
BinaryChromosome.java - Click Here
crossover - Jenetics - Click Here