An algorithm for converting a base-10 number to a base-N number

前端 未结 8 1776
有刺的猬
有刺的猬 2020-12-17 20:37

I am looking for a way to convert a base-10 number into a base-N number where N can be large. Specifically i am looking at converting to base-85 and back again. Does anyone

8条回答
  •  爱一瞬间的悲伤
    2020-12-17 21:27

    Just a general pseudocode algorithm:

    1. initialize empty list
    2. take current number mod base, store result at front of list
    3. divide current number by base and floor it (integer division does this perfectly)
    4. if result is still greater than zero, repeat at #2

提交回复
热议问题