基地10到n进制转换 [英] Base 10 to base n conversions
问题描述
我试图解决一个问题,这需要知识基础的转换。更precisely,想要的十进制数转换为其他所有的整数碱基(从2到20)。我已经搜查了一下,我发现了一些算法来解决这个问题,但他们都难以实现C / C ++。于是,我来到了我的问题:是否有一个高效,易于实现算法的基础转换?提前致谢。
I'm trying to solve a problem, which requires knowledge in base conversions. More precisely, you want to convert a decimal number to all the other integer bases ( from 2 to 20 ). I have searched it a bit and I have found some algorithms to solve this problem, but they are all difficult to implement in C/C++. So, I come to my question: Is there an efficient and easy-to-implement algorithm for base conversions? Thanks in advance.
推荐答案
我不明白到底是哪里的问题呢?这很容易和straigtforward做进制转换:你这样做,你会用手
I don't understand where exactly is the problem? It's very easy and straigtforward to do base conversion: you do it as you would by hand.
- 划分的号的通过的基础的
- 写下来,其余
- 与除法的整数部分重复这个过程
- 停止,当你达到零
- 在相反的顺序余给你在的基础位数的
- divide the number by base
- write down the remainder
- repeat the process with the integer part of the division
- stop when you reach zero
- the remainders in reverse order give you the digits in base
例如:
1025(十进制)立足15:
1025 (decimal) to base 15:
1025 / 15 = 68 , remainder 5
68 / 15 = 4 , remainder 8
4 / 15 = 0 , remainder 4
在底座15的数量是485
The number in base 15 is 485
这篇关于基地10到n进制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!