• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Int Val of Hex From NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: Int Val of Hex From NSData
      • From: Christian Longshore Claiborn <email@hidden>
    • Re: Int Val of Hex From NSData
      • From: David Remahl <email@hidden>
References: 
 >Re: Int Val of Hex From NSData (From: "Clark S. Cox III" <email@hidden>)

  • Prev by Date: RE: Code for parsing Objective-C files?
  • Next by Date: Re: Grep Support in Cocoa
  • Previous by thread: Re: Int Val of Hex From NSData
  • Next by thread: Re: Int Val of Hex From NSData
  • Index(es):
    • Date
    • Thread