Efficient algorithm for conversion between numeral system

后端 未结 1 1891
梦毁少年i
梦毁少年i 2021-01-06 01:10

Is there any efficient algorithm for conversion between numeral system when the size of source integer is arbitrary?

For example, assume that there is an integer arr

相关标签:
1条回答
  • 2021-01-06 01:30

    Divide by the base, push back the module, rinse and repeat while quotient != 0.

    So, for example convert 148 in base 16

    148 / 16 = 9 r 4
      9 / 16 = 0 r 9
    

    So, 148 in hex is 0x94. This shouldn't take so long.

    0 讨论(0)
提交回复
热议问题