convert char to byte
Posted on 2004-11-26
i need to read a file, calculate its SHA-1, and then encode each byte in the SHA-1 digest as %hh , (i.e., from a 20 byte SHA-1 value, i need to get a string of length 60) .
anywayz, i wrote the code, and then found that the string of length 60 was coming out wrong, so i began verifying whether each step in the entire process was working or not .. anywayz, i found a problem ... i think ..
(1) i read the file using bufferedreader into a char array
(2) for testing, i copy char by char into a byte array
( b[i]=(byte)c[i]; )
(3) (yet for testing) i copy byte by byte back into a char array
( c1[i]=b[i]; )
(4)i then write this char array using bufferedwriter into a file ..
however, the output file contains a lot of junk (lots of '?' characters), even though it should match the input file ..
can anyone help me out ??