• 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: How do you convert a byte array to a int or long, NSNumber has not byte init method.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you convert a byte array to a int or long, NSNumber has not byte init method.


  • Subject: Re: How do you convert a byte array to a int or long, NSNumber has not byte init method.
  • From: "Shawn Erickson" <email@hidden>
  • Date: Mon, 7 May 2007 11:20:35 -0700

On 5/7/07, Martin <email@hidden> wrote:
I want to create a int or long from a series of bytes that are in a
NSData object.  It does not appear that a NSNumber object can be
created from a byte array, I normally use Java and could create a
BigDecimal using a byte array in the constructor.

What data type do I use to create a buffer for the call [dataObject
getBytes:buff range:aRange]

I know that the range I want is either 4 or 2 bytes, i.e.
NSRange fourBytes = {8,4}
NSRange twoBytes = {16, 2}

UInt12 twoByteValue; UInt32 fourByteValue;

[dataObject getBytes:&twoByteValue range:twoByteRange];
[dataObject getBytes:&fourByteValue range:fourByteRange];

Of course just make sure your ranges are correct and match up with the
buffer you supply in terms of length or bad things, like security bad,
can happen. Also you may have to deal with byte swapping in the above
depending on the source/destiniation of the data.

-Shawn
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: How do you convert a byte array to a int or long, NSNumber has not byte init method.
      • From: "Shawn Erickson" <email@hidden>
References: 
 >How do you convert a byte array to a int or long, NSNumber has not byte init method. (From: Martin <email@hidden>)

  • Prev by Date: How do you convert a byte array to a int or long, NSNumber has not byte init method.
  • Next by Date: Re: How do you convert a byte array to a int or long, NSNumber has not byte init method.
  • Previous by thread: How do you convert a byte array to a int or long, NSNumber has not byte init method.
  • Next by thread: Re: How do you convert a byte array to a int or long, NSNumber has not byte init method.
  • Index(es):
    • Date
    • Thread