I'm trying to implement WebSocket handshake (76) in ObjC and can't figure out (as I'm new to C and ObjC) how can I get the following:
- List item
I've got two number
155712099 173347027开发者_如何学运维
I need to convert them to 32 bit big-endian numbers
- concatenate them into a string
- and express the resulting string in ASCII
Help is highly appreciated.
Since you're using the iPhone SDK, you have access to Core Foundation. Use:
uint32_t myInt32Value = ...;
uint32_t myInt32AsABigEndianNumber = CFSwapInt32HostToBig(myInt32Value);
Objective-C is based on C and usually has the C standard library available, so you can use the standard htonl
function. You can then do the string manipulation using the normal string functions.
精彩评论