Skip to content

Instantly share code, notes, and snippets.

@TonnyXu
Last active December 12, 2015 09:09
Show Gist options
  • Save TonnyXu/4749305 to your computer and use it in GitHub Desktop.
Save TonnyXu/4749305 to your computer and use it in GitHub Desktop.
//
// main.m
// NSStringHash
//
// Created by Tonny Xu on 2/10/13.
// Copyright (c) 2013 Tonny Xu. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSString *s = @"Hello, World!";
NSUInteger hashCode0 = s.hash;
CFHashCode hashCode1 = CFStringHashNSString(s);
CFHashCode hashCode2 = __CFStringHash(s);
NSLog(@"%ld", hashCode0);
NSLog(@"%ld", hashCode1);
NSLog(@"%ld", hashCode2);
NSLog(@"%lX", hashCode0);
NSLog(@"%lX", hashCode1);
NSLog(@"%lX", hashCode2);
NSString *longStrMoreThan96 = @"1234567890123456789012345678901_abcdef_234567890123456789012345678901_abcdef_2345678901234567890123456789012";
NSString *longStrIs96 = @"1234567890123456789012345678901_ABCDEF_234567890123456789012345678901_ABCDEF_2345678901234567890123456789012";
NSLog(@"%ld", longStrMoreThan96.hash);
NSLog(@"%ld", longStrIs96.hash);
NSLog(@"%lX", longStrMoreThan96.hash);
NSLog(@"%lX", longStrIs96.hash);
}
return 0;
}
2013-02-10 21:12:57.704 NSStringHash[25996:303] 3294171457232409974
2013-02-10 21:12:57.707 NSStringHash[25996:303] -1315859082
2013-02-10 21:12:57.707 NSStringHash[25996:303] -1315859082
2013-02-10 21:12:57.707 NSStringHash[25996:303] 2DB73F7CB1919576
2013-02-10 21:12:57.708 NSStringHash[25996:303] FFFFFFFFB1919576
2013-02-10 21:12:57.708 NSStringHash[25996:303] FFFFFFFFB1919576
2013-02-10 21:12:57.708 NSStringHash[25996:303] -8069816457736624960
2013-02-10 21:12:57.709 NSStringHash[25996:303] -8069816457736624960
2013-02-10 21:12:57.709 NSStringHash[25996:303] 900240AFFA01E4C0
2013-02-10 21:12:57.710 NSStringHash[25996:303] 900240AFFA01E4C0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment