tags:

views:

92

answers:

2

I'm writing an iphone apps that receive data from an udp socket i can dispay what i receive using NSDATA description but is in hex format and for example it look like this:

<4c61742c 34343039 3131302e 35302c4c 6f6e2c39 38343237 352e3934 2c482c32 37392e30 302c4b6e 6f74732c 302e3032 2c4e616d 652c504c 41594552 2c496e64 65782c30 2c4d756c 7469706c 61796572 4e756d62 65722c30 00>

i know that thi is a prase of compite sens how i can convert it ?

A: 
NSString * s = [[[NSString alloc] initWithData:yourData encoding:NSUTF8StringEncoding] autorelease];
Dave DeLong
That will fail if the data does not represent a UTF-8 string.
JeremyP
@JeremyP correct; you'd need to use the proper string encoding for the data you have. I've found that NSUTF8 is a decent default encoding to use.
Dave DeLong
A: 

I'm going to assume you want to just debug the binary data. If that's not the case, what I describe below won't be terribly useful.

One technique I like is to use 0xED. Copy that big binary dump (everything inside the angle brackets) and paste it into a newly created 0xED document. You get a nice hex editor view.

0xED also supports user-defined plugins which can help visualize the binary data (for instance, converting an 8 byte timestamp to an NSDate)

nall