Yes if you limit the character set as specified you can actually pack 3
characters per integer. It is a techniques called Rad50 that the old
PDP11 assemblers used to use for speed. I wrote a cross assemble many
years ago (early 90s i think) that duplicated the method.
Following is some really bad C code i wrote long ago before I knew how
to be a better programmer. Hopefully it helps you. I actually combine
two 32 bit words to make one long int. This way one long compare checks
6 characters. The long word served as a key in a btree.
#define getrad50(x) ((long)(rad50table[(uchar)x]))
/* Rad50 coversion table */
char rad50table[256] =
{
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,27,-1,-1,-1,
-1,-1,-1,-1,-1,-1,28,-1,30,31,
32,33,34,35,36,37,38,39,-1,-1,
-1,-1,-1,-1,-1, 1 ,2, 3, 4, 5,
6, 7, 8, 9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,
26,-1,-1,-1,-1,29,-1, 1, 2, 3,
4, 5, 6, 7, 8, 9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23,
24,25,26,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1
};
/* get next characters and put as worksym */
void getworksym()
{
char *cptr = currentchar;
short j;
ushort r50a = 0,r50b = 0;
/* get first 3 characters */
if ((j = (short)getrad50(*cptr++)) >= 0)
{
r50a = j * 1600;
if ((j = (short)getrad50(*cptr++)) >= 0)
{
r50a += j * 40;
if ((j = (short)getrad50(*cptr++)) >= 0)
{
r50a += j;
/* get second 3 characters */
if ((j = (short)getrad50(*cptr++)) >= 0)
{
r50b = j * 1600;
if ((j = (short)getrad50(*cptr++)) >= 0)
{
r50b += j * 40;
if ((j = (short)getrad50(*cptr++)) >= 0)
{
r50b += j;
for (;getrad50(*cptr++) >= 0;);
}
}
}
}
}
}
worksym = ((long)r50a << 16) | r50b; /* make long rad50 character */
getnextchar(--cptr);/* get next non white space */
}
Hope this helps
Leon Lambert
Mantorok wrote:
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
>On Apr 3, 10:55 am, "Mantorok" <n...@none.comwrote:
>>Hi, again I should've explained better, my resulting integer is limited
to
999, silly I know but this is the constraint I'm working against.
I personally think it will be impossible as the chars are made up of 2
values and the integer is only 1.
Well, that's not the problem. The problem is that even if you limit
yourself to A-Z, a-z, 0-9 for each of the characters, that's still 62
characters, giving 62*62=3844 possible combinations - you can't
represent that in the integers 0-999.
Well, it's one of the problems, but yes you are right, the other problem is
there is no way to map the number of possible combinations, which is another
approach that could've been taken.
Kev