Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

c++ - Adding base62 numbers

Say, one's got a base62 number (alphabet: [aAbBcC-yYzZ0-9]) char *num="abcd". The alphabet used to create such a number consists of letters in non-alphabetical order! ('A' after 'a', not 'b').

How to get the next number of the sequence (how to add 1 to base62 number)? Next is "abce" and previous is "abcc". I'd appreciate it if you provide me with some code.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The usually-best answer to questions such as How do I compute in base N ? is

convert from base-N to base-2 (trivial if N==2, easy enough otherwise), use the lightning-fast, hardware-implemented features of your computer to calculate in base-2, then convert from base-2 to base-N.

While rejecting my absurd suggestion consider how your computer fools you into thinking that it does base-10 arithmetic.

Note carefully that this approach complies with OP's strict instruction to avoid converting numbers to base-10.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...