Re: Int Val of Hex From NSData
Re: Int Val of Hex From NSData
- Subject: Re: Int Val of Hex From NSData
- From: "Clark S. Cox III" <email@hidden>
- Date: Mon, 10 Mar 2003 10:32:55 -0500
On Monday, Mar 10, 2003, at 10:05 US/Eastern, Seth Willits wrote:
If I have an NSData object that has three bytes in it (A9B), how can I
get the integer equivalent (2715)?
I'm assuming that you actually mean 3 bytes (and not 3 hex characters)
This should do it:
const unsigned char *bytes = [nsData bytes]
unsigned int value;
NSAssert([nsData length] >= 3);
value = bytes[0] << 16 | bytes[1] << 8 | bytes[2];
--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.