Re: int to bytes(value in NSString)
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