XCode base_convert

2019-08-12 10:53发布

问题:

I am developing iOS application and I need base_convert function. Application is communicating with PHP server using base_convert, too. In PHP I use this:

base_convert($something,16,36) and base_convert($something,36,16)

I search for something like I use in PHP, but for Xcode (iOS application). Thank you.

回答1:

there is a C++ implementation here:

http://thinkdiff.net/mixed/base-conversion-handle-upto-36-bases/

that will convert back and forth with bases up to 36. Not sure if you need more than that.



回答2:

There is a complete wikepedia page devoted to Base 36 with various forms of source code that you could adapt (for example the C code should just drop straight in with no modification but is soooo not objective-c)

There is also how to convert Decimal to base36 which only does a one-way conversion, but the code is objective-c, so you could get an idea on how to adapt the wikepedia code.

As to why base 36 I learnt:

Base 36 is therefore the most compact case-insensitive alphanumeric numeral system using ASCII characters



回答3:

Adapted the code David Hope suggested into Objective-C, here:

https://gist.github.com/furkanmustafa/5660086