What is the currently know fastest algorithms to convert each individual Java primitive and Number types to a Char Array/String number representation while considering their range, endianess and layout, sign and JVM specifics? The algorithm used for say byte may differ from int due to the range. char would be a special case.

ryu gives floating-point to String conversions but not for the other primitive types.

There are some C/C++ solutions but I could not find any Java specific ones:

  • $\begingroup$ I'm sure that for integer types at least this can be done in time $O(1 + \log v)$, where $v$ is the absolute value of the number being converted. $\Omega(1 + \log v)$ is also a trivial lower bound since you need to spend at least constant time and examine at least $\Omega(\log v)$ bytes (to simply formulas assume $v \neq 0$). The fact that the language of choice is Java doesn't seem to be relevant as far as the algorithm's complexity is concerned. $\endgroup$ – Steven Nov 3 '20 at 10:05
  • $\begingroup$ What would this algorithm be? It need not be in Java. Would the sign, range of the numbers and endianness influence the algo? If so what adjustments would be needed to optimise for sign/unsigned, different ranges and byte order? $\endgroup$ – Suminda Sirinath S. Dharmasena Nov 3 '20 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.