Xnary (like binary but different) counting

后端 未结 3 570
感情败类
感情败类 2020-12-18 05:26

I\'m making a function that converts a number into a string with predefined characters. Original, I know. I started it, because it seemed fun at the time. To do on my own. W

3条回答
  •  一个人的身影
    2020-12-18 05:37

    This appears to be a very standard "implement conversion from base 10 to base N" where N happens to be 26, and you're using letters to represent all digits.

    If you have A-Z as a 26ary value, you can represent 0 through (26 - 1) (like binary can represent 0 - (2 - 1).

    BZ = 1 * 26 + 25 *1 = 51

    The analogue would be:

    19 = 1 * 10 + 9 * 1 (1/B being the first non-zero character, and 9/Z being the largest digit possible).

    You basically have the right idea, but you need to shift it so A = 0, not A = 1. Then everything should work relatively sanely.

提交回复
热议问题