Created
October 23, 2022 23:56
-
-
Save gonaumov/2b7eec9ab396da5f5e3f8842234e1323 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package converter | |
import java.math.BigInteger | |
class NumberConverter( | |
private val sourceBase: BigInteger, | |
private val targetBase: BigInteger | |
) { | |
private fun convertFromDecimal(decimalNumber: BigInteger): String { | |
return decimalNumber.toString(targetBase.toInt()); | |
} | |
/** | |
* This function converts the input string to decimal number | |
* system | |
*/ | |
private fun convertToDecimal(numberInput: String): BigInteger { | |
return numberInput.toBigInteger(sourceBase.toInt()); | |
} | |
fun convert(input: String): String { | |
val decimalNumber = convertToDecimal(input) | |
return convertFromDecimal(decimalNumber) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment