java - Convert long to "byte-array-ed" text, without heap allocations -


I would like to convert a (positive) primitive long to byte [] in my text form , In java

An easy way would be for example: 123 = & gt; "123" = & gt; [49, 50, 51]

Although for a long time it assigns a string to change the string and I am trying to avoid it, for my GC free library, I would like to present it directly on the pre-allocated byte array.

Therefore, my question is how do I go for a byte [] representation for a long time, if I have a string constructor (for example above) I am calling with "123" To clarify, I do not want to convert it into binary form as long as it is in the form of byte [] , but rather literally

Thank you! N

This simple program:

  long L = 123; Int size = (int) (Math.log10 (l) + 1); Byte [] array = new byte [shape]; For (int i = 0; i  

I tested it for the current time in milliseconds and acted as expected:

  LC = System Syrtetime milliseconds (); ... System.out.println (Arrays.toString (array));  

Output:

  1406485727149 [49, 52, 48, 54, 52, 56, 53, 55, 50, 55, 49, 52, 57 ]  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -