iOS Question CRC32 on ios

Discussion in 'iOS Questions' started by ldb68, Mar 2, 2015.

  1. ldb68

    ldb68 Member Licensed User

    I need help with a crc32 function on IOS

    From these link
    http://stackoverflow.com/questions/4115059/get-crc-checksum-of-an-nsdata-in-objective-c
    http://ios-blog.co.uk/tutorials/quick-tips/quick-tip-converting-nsstring-to-nsdata/

    I try this code

    Code:
    Dim NativeMe As NativeObject = Me
    Log(NativeMe.RunMethod("Crc32_String:"Array ("test")).AsString)

    #If OBJC
    #import <zlib.h>
    - (NSString*) Crc32_String: (NSString*) strdata {

    //NSString* strdata = @"1234567890";
    NSData* data = [strdata dataUsingEncoding:NSUTF8StringEncoding];
    data = [data subdataWithRange:NSMakeRange(0, [data length] - 1)];
    unsigned long result = crc32(0, data.bytes, data.length);
    NSString *str = [NSString stringWithFormat:@"%qi",result];
    return str;
    }
    #end if
    The result is non corretct
     
    Last edited: Mar 2, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    1. Add a reference to iAcrhiver library.
    2. Add this objc code:
    Code:
    #If OBJC
    #import <zlib.h>
    - (long long) crc32: (B4IArray*) data {
    long long result = crc32(0, data.bytesData.bytes, data.Length);
    return result;
    }
    #end if
    Call it with:
    Code:
    Dim nativeMe As NativeObject = Me
    Dim data() As Byte = "test".GetBytes("UTF8")
    Dim res As Long = nativeMe.RunMethod("crc32:"Array(data)).AsNumber
    The result is correct.
     
  3. ldb68

    ldb68 Member Licensed User

    Thank You

    Always the best
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice