• 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 to bytes(value in NSString)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: int to bytes(value in NSString)


  • Subject: Re: int to bytes(value in NSString)
  • From: Jeremy Pereira <email@hidden>
  • Date: Tue, 18 Aug 2009 14:44:37 +0100


On 18 Aug 2009, at 03:06, Graham Cox wrote:


On 17/08/2009, at 5:07 PM, bosco fdo wrote:

I need NSString in binary format how do i print NSString in binary format
instead of "0001"
obj-c code is uint8 barr[4];
barr[0] =(uint8)num;
barr[1] =(uint8)num>>8;
barr[2] =(uint8)num>>16;
barr[3] =(uint8)num>>24;


i am using [NSString stringwithFormat:@%i,barr[i]]

which %? i need to use to get the byte value(binary data) as it is from the
array?


This tells you:

http://www.opengroup.org/onlinepubs/009695399/functions/printf.html

It states that the default precision for %i is 1, but Apple appear to have changed it to 4 (???)

So try %i.1

The Apple version of %i conforms to spec. The default precision is 1 but the precision tells you the *minimum* number of digits that will be printed, not the actual number.


In any case, if the intention really is to insert the actual raw bytes into the string, the correct format specifier is %c. However, that is likely to mess things up badly if the value of a byte is 0.



--Graham


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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


References: 
 >int to bytes(value in NSString) (From: bosco fdo <email@hidden>)
 >Re: int to bytes(value in NSString) (From: Graham Cox <email@hidden>)

  • Prev by Date: RE: Overriding NSCollectionView's selection: a good idea?
  • Next by Date: Re: disabling tooltips table view
  • Previous by thread: Re: int to bytes(value in NSString)
  • Next by thread: How to manage NSArray, NSDictionary, ... description encoding for non ascii characters?
  • Index(es):
    • Date
    • Thread