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

后端 未结 7 1617
执笔经年
执笔经年 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

    To convert 214base5 to base 16 without an intermediate base, you "just" have to know how to calculate directly in base 5.

    First, you need a table of what the base 16 digits are in base 5 (you need a similar table when converting base 10 to base 16, it's just that that one is easier to keep in your head!). This table is easy to create - just start at 0 and increment each base 5 row until you reach f in base 16.

    base 16 | base 5
    --------+--------
          0 |  0
          1 |  1
          2 |  2
          3 |  3
          4 |  4
          5 | 10
          6 | 11
          7 | 12
          8 | 13
          9 | 14
          a | 20
          b | 21
          c | 22
          d | 23
          e | 24
          f | 30
    

    Now you just need to repeatedly divide by 16 (which is 31base5). We now recall our primary school days, and use long division (if this seems hard, it's because no-one made you learn your times-tables in base 5!):

    Step 1:

       ______
    31 ) 214
    

    Step 2:

           3 
       ______
    31 ) 214 -
         143  
    

    Step 3:

           3 
       _____
    31 ) 214 -
         143  
        ----
          21
    

    So the result of 214base5 divided by 31base5 is 3base5 remainder 21base5.

    This means that the least significant digit in base16 is 21base5, which you can find in the table is bbase16. The result of the division is 3base5 - if this was greater than 30base5 then we would divide again - but it's not, so this means the most significant digit is (using the table again) 3base16.

    So the answer is 214base5 = 3bbase16.

提交回复
热议问题