The naive approach is to use 4 local variables:
int chromatid1Start; int chromatid1End; int chromatid2Start; int chromatid2End;
Then assign incoming chromatid1 first two variables and chromatid2 last two variables.
chromatid1Start = chromatid1; chromatid1End = chromatid1; chromatid2Start = chromatid2; chromatid2End = chromatid2;
Perform a right shift on the Start chromatid variables to the crossover point, then shift the same amount to the left. On chromatid variables End , moving left to the crossover point, then shift the same amount to the right.
chromatid1Start = (chromatid1Start >> 16 * crossoverPercent) << 16 * crossoverPercent; chromatid1End = (chromatid1End << 16 * (1 - crossoverPercent)) >> 16 * (1 - crossoverPercent); chromatid2Start = (chromatid2Start >> 16 * crossoverPercent) << 16 * crossoverPercent; chromatid2End = (chromatid2End << 16 * (1 - crossoverPercent)) >> 16 * (1 - crossoverPercent);
With this, you can go to the beginning of one from the end of the other:
int daughterChromatid1 = chromatid1Start + chromatid2End; int daughterChromatid2 = chromatid2Start + chromatid1End;
saluce
source share