Thread: counting 16 bit number from a buffer

  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,336
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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, 10: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, 09:48 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM