mardi 24 février 2015

Java generic convert byte array to string (Non hex, decimal)



What is the best way to convert a byte array to a string with a radix of choice? There is a ton of examples here on S.O. and elsewhere to convert to a hex string. What I am mainly interested in here is converting to something other than a hex or decimal string; also a more generic way.


This is what I currently do:



Byte[] input;
String MyStr = new BigInteger(input).toString(radix);


This works, but since Java has a concept of radix, as used in the Integer. This seems to be the explicit purpose as defined in Character. Shouldn't there be a better way of doing this rather than to first convert the byte array to a BigInteger? It feels like my Java knowledge misses some essential standard class?




Aucun commentaire:

Enregistrer un commentaire