counting 16 bit number from a buffer

This is a discussion on counting 16 bit number from a buffer within the C Programming forums, part of the General Programming Boards category; how to count a 16 bit number from a buffer that has a unique value, crc doesnt fit me because ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    26

    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.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by tabstop View Post
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    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

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by baccardi View Post
    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.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting number of digits?
    By scatterice in forum C Programming
    Replies: 7
    Last Post: 05-12-2009, 01:30 PM
  2. Copying 32 bits into 16 bit integer???
    By blackCat in forum C Programming
    Replies: 4
    Last Post: 02-17-2009, 09:00 AM
  3. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  4. 16 bit compilar or 32 bit compilar
    By rajkumarmadhani in forum C Programming
    Replies: 16
    Last Post: 12-04-2007, 08:48 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21