Skip to content

Instantly share code, notes, and snippets.

@Tolsi
Created May 21, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tolsi/3b63990daaab63c13780db91f3309f89 to your computer and use it in GitHub Desktop.
Save Tolsi/3b63990daaab63c13780db91f3309f89 to your computer and use it in GitHub Desktop.
Scala base58 bytes array size by string and string length by bytes array size
object Base58Length {
private val BytesMaxValue = 256
private val Base58MaxValue = 58
private val BytesLog = math.log(BytesMaxValue)
private val BaseLog = math.log(Base58MaxValue)
def base58Length(byteArrayLength: Int): Int = math.ceil(BytesLog / BaseLog * byteArrayLength).toInt
def bytesLength(base58Length: Int): Int = math.ceil(BaseLog / BytesLog * base58Length).toInt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment