Encoding NSData into string containing only numbers and decoding back

148 Views Asked by At

Base64 uses lower and uppercase alphabet and also some special characters

Base32 is better, but still uses also alphabet characters (the output is larger than base64 of course)

How to encode a NSData into a number-only NSString?

As i can transmit only number characters '0'-'9'

1

There are 1 best solutions below

0
On BEST ANSWER

Some hints:

  1. NSData has methods to tell you how many bytes it represents and to provide a pointer to these bytes.
  2. A byte is just an integer type in (Objective-)C, as an unsigned value it represents decimal 0 to 255
  3. The string formatting methods can format an integer to a fixed number of digits using leading zeros, e.g. 004.

HTH