Hi all Sorry if i am not clear. But i need to group all binary format data together in my logic for that i need to convert some integer to binary format(byte value?) the below java code make the conversion correct
private byte[] int2bin(int i) { byte[] value = new byte[4]; value[0] = (byte) ((i >>> 24) & 0xff); value[1] = (byte) ((i >>> 16) & 0xff); value[2] = (byte) ((i >>> 8) & 0xff); value[3] = (byte) ((i) & 0xff); return value; } I need to make the equvalent thing in obj-c as below 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]] if i use %i i am getting "0001" which i cannot use it together with other binary format data [the correct output format will be some 4 square like chars ] is it the format which i need is byte char? or binary format? [ not "0 and 1" format ] if i use %c i am getting empty NSString so is the logic to convert from int to bin is wrong? Please correct. thanks bos On Wed, Aug 19, 2009 at 9:30 AM, bosco fdo<bos1t...@gmail.com> wrote: > Hi all > I dont want in binaries('1', '0'), > but i want to convert int to bytes(byte value string) > > for example in java working code when i convert int value 1 to byte > value in 4 square like chars(unreadable format) > > the same thing i need to do in objective c > > thanks for the help > > bos > > > > On Tue, Aug 18, 2009 at 2:56 PM, Andrew Farmer <andf...@gmail.com> wrote: >> >> On 17 Aug 2009, at 23:21, 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 >> >> Wait, you're trying to construct a NSString with null bytes in it? I'm >> pretty sure that doesn't work correctly in a lot of circumstances - NSString >> is primarily intended for representing a sequence of characters, not an >> arbitrary set of bytes. What you probably want instead is NSData. > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com