2014-04-10 12:10



I know that base 16 uses the characters [0-9a-f], and base 36 uses [0-9a-z], but what about base 40? Base 50? Base [arbitrary number]? How does php determine what characters to use for high-base numbers?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dpz90118 dpz90118 7年前

    PHP won't "determine" symbols for just any arbitrary base. Because base_convert() allows conversions for bases between 2 and 36 only. Thus, it's not allowed to use it for base 50, for example:

    Both frombase and tobase have to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35.

    I assume that it is about base_convert() since only this function has direct relation to the question

    As for base_convert(): internally, it will do _php_math_zvaltobase() call where char map is defined:

    static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
    点赞 评论 复制链接分享