Toshiba Mini nb305-n440bn 10.1" netbook...

The given algorithm produces combination's of GATC of length 5.When I try to replace GATC with 12345678 it produces the output of first four numbers of unit length 5.Can any one help me in understanding the program? #include <stdio.h>

typedef unsigned char cell;

cell a[1000];

int npack = sizeof(cell)*4;void decode(cell * a, int nbsym)

{

unsigned i;

for (i=0; i < nbsym; i++){

printf("%c", "GATC"[a[i/npack]>>((i%npack)*2)&3]);

}

printf("\n");

}void enumerate(cell * a, int nbsym)

{

unsigned i, j;

for (i = 0; i < 1000; i++){

a[i] = 0;

}

while (j <= (nbsym / npack)){

j = 0;

decode(a, nbsym);

while (!++a[j]){

j++;

}

if ((j == (nbsym / npack))

&& ((a[j] >> ((nbsym-1)%npack)*2)&4)){

break;

}

}

}int main(){

enumerate(a, 5);

}

unsigned i, j;

Obvious error:jisn't initialized. This gives you a (1 + nbsym / npack) in 4,294,967,296 (ifintis 32-bit) chance yourwhileloop will run.

it produces the output of first four numbers of unit length 5

This program is packing four values into a singlecell, over two bits. This works because 2 raised to the second power is 4. (Side note: this implementation wastes space if the platform's byte is ever greater than 8 bits.)If you wanted to use "12345678," the program would need to be refactored to store its values over 3 bits. And then you end up with octal, only with misleading symbols.

Ask Your Question

Weekly Poll