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

前端 未结 8 1582
有刺的猬
有刺的猬 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
    0 讨论(0)
  • 2020-12-17 21:27

    The simplest algorithm that I can think of is (in pseudo-code):

    N = base-10 number
    1) N mod 85 = 1st number
    2) tempVal = floor(N/85)
    3) if(tempVal > 0 && tempVal < 85) then
        tempVal= 2nd number
    else
        2nd number = (tempVal mod 85), then goto step (2), replacing N with N1
    
    0 讨论(0)
提交回复
热议问题