Tutorial :How to convert NSString of Decimal to NSString of Bytes



Question:

I have a very big integer value in decimal which i put in NSString , i need to convert to NSString of Bytes value for this big value how can i do it? FYI the length of NSSting is "308"

Please help

Thanks


Solution:1

To do this, you'll need to do the following(assuming you want a UTF8-encoded byte stream):

NSString *myString; //Assuming your string is here  NSData *stringData = [myString dataUsingEncoding:NSUTF8StringEncoding]; //This is the NSData representation of the string  const void *bytes = [stringData bytes]; //This are the raw bit array values  


Solution:2

What do you mean "string of bytes"?

In particular, an NSString can only encapsulate strings with valid unicode (and some more primitive non-unicode) encodings. Thus, "string of bytes" may not actually make sense.

If you really want raw bytes, you can convert it to an NSData instance using the dataUsingEncoding:* methods (there are two, depending on need).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »