Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created October 23, 2022 23:56
Show Gist options
  • Save gonaumov/2b7eec9ab396da5f5e3f8842234e1323 to your computer and use it in GitHub Desktop.
Save gonaumov/2b7eec9ab396da5f5e3f8842234e1323 to your computer and use it in GitHub Desktop.
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