objective c - NSString to NSData conversion to Hex Value -


this question has answer here:

i've been trying convert user defaults nsstring (tried nsdata also), hex value can use char array. problem every time convert nsstring or nsdata takes hex values , turns them ascii values, isn't want @ all. how tell literally take values there , keep them hex? i'm struggling find solution.

inside .plist

<key>shit</key> <string>5448495344414e475448494e474e45454453544f53544159484558</string> 

my code convert nsstring nsdata

  nsstring *defaults = [[nsuserdefaults standarduserdefaults] objectforkey:@"shit"];     nsdata *thedata = [defaults datausingencoding:nsutf8stringencoding];     nsuinteger datalength = [thedata length];     byte *bytedata = (byte*)malloc(datalength);     memcpy(bytedata, [thedata bytes], len);  nslog(@"this : %@",[nsdata datawithbytes:bytedata length:len]); 

output:

this : <35343438 34393533 34343431 34653437 35343438 34393465 34373465 34353435 34343533 35343466 35333534 34>len 

why in world doing this? want original hex values, not interpretation of hex values.

a byte neither hex nor ascii nor octal nor int nor float, etc, different ways display and/or think byte(s). way nslog displays objects dictated way objects's description method written. nslog of nsdata , nsstring display same bytes differently.

if want access bytes in nsdata access them directly: thedata.bytes, no need tomemcpy`.

lastly , importantly: trying accomplish?

new developers served getting book on "c" language , studying it--that did.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -