Convert a number from Base B1 to Base B2 without using any intermediate base

后端 未结 7 1712
执笔经年
执笔经年 2021-02-02 15:47

Is there a way Convert a number from Base B1 to Base B2 without using any intermediate base.

Ex:

214 from base 5 to base 16 without converting it first to decima

7条回答
  •  旧巷少年郎
    2021-02-02 16:17

    Yes and no. Yes if you don't include the fact that the computer does everything in binary (base 2) as another representation. After all, what is the base of value in the following code?

    long value = strtol(string, NULL, base);
    

    In some senses value is just an integer, and has no associated base. Combine that with a function to convert from a value to a string representaton in a particular base and you can easily from a string representation in one base to a string representation in another base. Since there's no intermediate string representation there is, is some sense, no intermediate base value.

提交回复
热议问题