Hay guys,
I was looking at a few examples of how a Radix sort works, and writing up a document explaining it. I based my findings on one particular example I found, link follows.
http://www.cubic.org/docs/radix.htm
Well the bit shifting here is giving my head a bit of a spin, and I was wondering if someone could lay it out on the table for me so I can understand. I know what he is doing, he gets the key he is sorting and looks at the ones column, then continues, second pass he bit shifts the key by 8 bits, and so on up to 24 bits on the last pass. The following bit of code though I need a bit of help on.
void radix (int byte, long N, long *source, long *dest)
{
long count[256];
long index[256];
memset (count, 0, sizeof (count));
for ( int i=0; i<N; i++ ) count[((source[i])>>(byte*8))&0xff]++;
index[0]=0;
for ( i=1; i<256; i++ ) index[i]=index[i-1]+count[i-1];
for ( i=0; i<N; i++ ) dest[index[((source[i])>>(byte*8))&0xff]++] = source[i];
}
Now with this line,
for ( i=0; i<N; i++ ) dest[index[((source[i])>>(byte*8))&0xff]++] = source[i];
Could someone please run a number through it and show me step by step how it is actually getting the ones column, tens, hundreds and so on. I also have no clue to what the, ")&0xff" is doing.
Thanks in advance for any help!