Re: Int Val of Hex From NSData
Re: Int Val of Hex From NSData
- Subject: Re: Int Val of Hex From NSData
- From: Seth Willits <email@hidden>
- Date: Mon, 10 Mar 2003 14:46:45 -0800
On Monday, March 10, 2003, at 07:32 AM, Clark S. Cox III wrote:
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];
Seriously? Wow... I'm just very used to higher level languages then.
So there isn't any
int = [[NSData subdataWithRange:range] integerValue]
or what about:
NSString = [[NSData subdataWithRange:range] stringValue]
or
[NSData setBytes: NSData atOffset: int length: int]
Strange...
Seth Willits
------------------------------------------------------------------------
---
President and Head Developer of Freak Software -
http://www.freaksw.com
Q&A Columnist for REALbasic Developer Magazine -
http://www.rbdeveloper.com
"To be a great is to be misunderstood."
-- Ralph Waldo Emmerson
------------------------------------------------------------------------
---
_______________________________________________
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.