How do I convert an NSString into a 16 bit int

  • Does anyone have any suggestions for how to convert an NSString into a
    16 bit int? I have checked Google and can only find ways of creating
    an MD5 hash that is much , much longer. I am looking for something
    similar to an MD5 hash I just need it to be 16 bits not 128. I am also
    hoping that I don;t have to become an expert in cryptography to do this.

    Thanks,
    Mike
  • On Nov 25, 2007 2:22 PM, Michael Swan <michaelswan...> wrote:
    > Does anyone have any suggestions for how to convert an NSString into a
    > 16 bit int? I have checked Google and can only find ways of creating
    > an MD5 hash that is much , much longer. I am looking for something
    > similar to an MD5 hash I just need it to be 16 bits not 128. I am also
    > hoping that I don;t have to become an expert in cryptography to do this.

    If you're not after something cryptographically secure, and you don't
    care about speed, use the MD5 hash and just take the first 4 hex
    digits (16 bits). Alternatively, grab some CRC-16 code from somewhere
    and use that. It'll all depend on the purpose you are using the result
    for.

    Dave.
  • On Nov 24, 2007, at 7:22 PM, Michael Swan wrote:

    > Does anyone have any suggestions for how to convert an NSString into
    > a 16 bit int? I have checked Google and can only find ways of
    > creating an MD5 hash that is much , much longer. I am looking for
    > something similar to an MD5 hash I just need it to be 16 bits not
    > 128. I am also hoping that I don;t have to become an expert in
    > cryptography to do this.
    >

    Depending upon the purpose to which you are going to put this 16 bit
    int, you could probably just take the low 16 bits of the return value
    of the -hash method.

    - Greg
  • On Nov 24, 2007, at 7:22 PM, Michael Swan wrote:

    > Does anyone have any suggestions for how to convert an NSString
    > into a 16 bit int? I have checked Google and can only find ways of
    > creating an MD5 hash that is much , much longer. I am looking for
    > something similar to an MD5 hash I just need it to be 16 bits not
    > 128. I am also hoping that I don;t have to become an expert in
    > cryptography to do this.
    >
    > Thanks,
    > Mike

    I needed a pseudo-random number generated from a string and used
    libcrypto to do do this. See section 11 here:

    http://www.bagelturf.com/cocoa/rwok/rwok2/index.html

    This is all Tiger and XCode 2.4, so things are likely different with
    the current toolset.

    --
    Blog:  http://www.bagelturf.com/  Photos: http://
    bagelturf.smugmug.com/  Buy my book: http://www.bagelturf.com/
    products/getyourheadaroundaperture/
previous month november 2007 next month
MTWTFSS
      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 27 28 29 30    
Go to today