Converting a singned decimal to a hexed String ?

Hi...

what i'm trying to do is to convert a buffer[8] which is filled with signed decimal values to a String Hex represenation of it.... This is the code i'm doing ..

/CODE/

for(int i = 0; i < 8; i++)

{

String serialStr = "";

serialStr = serialStr.concat( Integer.toHexString(hashed_Output) );

}

/CODE/

Now the return value of serialStr is the rigth hex values of hashed_Output[] but i get each value as ffffffCf let's say instead of only Cf. I guess because the value i'm reading is signed. Do u have any idea how to read those signed values to a string as hex and only show Cf ?

Please let me know...

[690 byte] By [geotdw] at [2007-9-26 1:52:42]
# 1
How about Integer.toString(int i, int radix) with radix=16. You'll still have to wacth out for the "-"-character.Or maybe not... You wanted ffffffcf to become cf. Integer.toHexString(i & 255) ?
jsalonen at 2007-6-29 3:02:49 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
thanks manit worked perfect (i & 255)
geotdw at 2007-6-29 3:02:49 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3
Just a note of caution. (i & 255) will work as long as your buffer[] is of type byte. If it is short, for example, then i & 255 will limit the values to 0x00 to 0xff. Your post didn't say what type buffer[] is.
atmguy at 2007-6-29 3:02:49 > top of Java-index,Archived Forums,New To Java Technology Archive...