How can I convert a number in a string to any base in assembly?

前端 未结 2 1860
一生所求
一生所求 2021-01-25 16:56

How can I convert a number contained in a string from any base to any other base?

Bases can be anything i.e.: 2, 16, 10, 4, 8, 9.

I\'m expecting the user to ente

2条回答
  •  抹茶落季
    2021-01-25 17:24

    The general algorithm for changing a number n to base b goes something like:

    i = 0
    while(n != 0)
       answer[i] = n mod b
       n /= b
       i++
    

    (Note that answer[0] holds the least significant digit of the answer.) Does this make sense? Which part of this pseudocode are you having trouble implementing?

提交回复
热议问题