Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...