tags:

views:

357

answers:

2

Hi I dont understand of the below case of converting int to byte , the below java code can able to print the byte value as below

System.out.println("binary output ::: "+Byte.toString(bo[0]));
System.out.println("binary output ::: "+Byte.valueOf(bo[1]));
System.out.println("binary output ::: "+Byte.valueOf(bo[2]));
System.out.println("binary output ::: "+Byte.valueOf(bo[3]));
System.out.println("binary output ::: "+new String(bo));

binary output ::: 0
binary output ::: 0
binary output ::: 0
binary output ::: 1
binary output ::: squaresquaresquaresquare ( 4 square chars) - binary data

but when i make a objective-c code to the same data into final NSString it also prints as "0001" but not in binary format ( 4 square chars)

I need NSString in binary format how do i print NSString in binary format instead of "0001"

please help

+1  A: 

The string is printing the integers, because that's what you're putting into it (%i == integer). %c is the token for characters.

Or, you can just pass the array into -[NSString initWithBytes:length:encoding:]. If you a string with a single byte, use the same method, passing an offset pointer into the array, and a length of one.

kperryua
Hi kperryI have tried but i am not getting the byte value copied into NSString , any idea?
I'd have to see the code you used when you tried it to help you any more.
kperryua
A: 

Hi kperry NSString *str = [ [NSString alloc] initWithBytes:barr length:sizeof(barr) encoding:NSUTF8StringEncoding]];

I have tried ASCII necoding also , but it only gives empty string only.