Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Forked from Nurdok/python_conversion.md
Last active December 16, 2015 11:18
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 chris-martin/5426294 to your computer and use it in GitHub Desktop.
Save chris-martin/5426294 to your computer and use it in GitHub Desktop.

Scala Number Conversion Chart

From → To Expression
45 → "45" data.toString
45 → "101101" BigInt(data).toString(2)
45 → "2d" BigInt(data).toString(16)
45 → Array[Byte](0, 0, 0, 0x2d)
"45" → 45 data.toInt
"45" → "3435" data.map(BigInt(_).toString(16)).mkString
"101101" → 45 BigInt(data, 2).toInt
"2d" → 45 BigInt(data, 16).toInt
"2d" → Array[Byte](0x2d)
Array[Byte](0, 0, 0, 0x2d) → 45
Array[Byte](0x2d) → "2d"
"3435" → "45" data.grouped(2).map(BigInt(_, 16).toChar).mkString

This is a fork of a similar chart for Python - https://gist.github.com/Nurdok/4096182 - There are a few missing rows because I'm not sure I know Python well enough to get exactly what those conversions are trying to accomplish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment