• 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: Graham Cox <email@hidden>
  • Date: Tue, 18 Aug 2009 17:09:17 +1000


On 18/08/2009, at 4:21 PM, bosco fdo wrote:

Hi graham
Thanks for the reply. I have tried %i.1 but i am getting 0.10.10.10.1 , but i need it in binary byte value


bos



Sorry, I meant %.1i

However it's not really clear what you're trying to do - do you want to display the binary of some data as a string? e.g. "0100010101010111"?

A byte will not be just 0 or 1, so your approach is not going to work anyway. Off the top of my head, this code will return the 8-bit binary of a byte as a string:

- (NSString*)	binaryStringWithByte:(uint8) byte
{
    uint8 mask = 0x80;
    NSMutableString*	str = [[NSMutableString alloc] init];

    while( mask )
    {
        [str appendString:(byte & mask)? @"1" : @"0"];
        mask >>= 1;
    }

    return [str autorelease];
}

--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


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

  • Prev by Date: Re: int to bytes(value in NSString)
  • Next by Date: Last look of my IPhone project
  • Previous by thread: Re: int to bytes(value in NSString)
  • Next by thread: Re: int to bytes(value in NSString)
  • Index(es):
    • Date
    • Thread