Java - Recursion Program - Convert a base 10 number to any Base

后端 未结 5 587
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 07:30

I am trying to convert a base 10 number to any base by using conversion. Right now this is the code I have came up with. I have a sad feeling this may be completely wrong. The

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-06 07:47

    If you are just trying to convert bases (like to base 2), try the following code:

    Integer.parseInt(Integer.toString(numberToConvert,base))

    For specifically base 2:

    Integer.parseInt(Integer.toBinaryString(numberToConvert))

    Integer contains other methods such as toHexString that can be used. These assume that numberToConvert is in base 10.

提交回复
热议问题