-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
GianpieroP wrote:
"Chris" <ch*******@hotmail.com> ha scritto nel messaggio
news:UzfYb.18042$Hy3.8786@edtnps89... Hi,
Or, even more concise, how about a call to
java.lang.{Integer|Long}.toHexString()?
Heh... don't re-invent the wheel :)
Ok! So my class loses one method: "... hexify(byte byValue)" and one
member: "HEX". But my "wheel" is useful again because it presents
"String hexify(byte[] byArr)" static method. However I'm happy if
you offers me another existent "wheel" in substitution of my
hexify(byte[] ) method.
Bye bye,
GianpieroP
Heh... actually, if working with large values, how about
:
public static String hexify(byte[] data) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < data.length; i++) {
sb.append(Integer.toHexString(((int) data[i]) & 0xFF));
}
return sb.toString();
}
The use of StringBuffer is the real point I'm making here, since it's
more efficient than repeated String concatenations. Also, since
Integer.toHexString() takes an int, you have to do the casting
oddness to prevent, say, -1 from turning into 0xFFFFFFFF. Other than
that, your method and mine are about the same. So that's my 2-cent
wheel :)
- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQFAMqqQnwjA8LryK2IRAiX5AJ4yBjkHA7uH/iwuPcee5upCBoPjUACfXqYH
bTDHAQpDgKzGA4/uCERa7sE=
=z+U/
-----END PGP SIGNATURE-----