counting 16 bit number from a buffer

• 02-20-2009
baccardi
counting 16 bit number from a buffer
how to count a 16 bit number from a buffer that has a unique value, crc doesnt fit me because it returns the same value for 'ab' and 'ba' and what i need is two different values. Is it at least possible? if so, maybe someone knows any algorithms to achieve what i want.
• 02-20-2009
tabstop
If your buffer is larger than two characters then it's hopeless, since you have more possibilities than answers and two strings will have to go to the same 16-bit integer. If your buffer is two characters exactly, then you are done, because two characters is a 16-bit integer.
• 02-20-2009
vart
Quote:

Originally Posted by tabstop
If your buffer is larger than two characters then it's hopeless, since you have more possibilities than answers and two strings will have to go to the same 16-bit integer. If your buffer is two characters exactly, then you are done, because two characters is a 16-bit integer.

If possible characters are from some known range like only a-z we can use compression and put more then 2 chars into the available for unsigned short range
• 02-20-2009
baccardi
but the thing is I have only 65536 different buffers(strings), so theoreticaly every buffer is able to have a different value, but the buffers arent fixed size and every char is in the range 0..255
• 02-20-2009
vart
Quote:

Originally Posted by baccardi
but the thing is I have only 65536 different buffers(strings), so theoreticaly every buffer is able to have a different value, but the buffers arent fixed size and every char is in the range 0..255

so you want a hash function that will give unique index for each of your buffers? it is impossible to write such function without knowing the buffer contents or lows of buffer creation.