I m new in java.I have a text document with hexadecimal values line by line, i m trying to read it and convert it into byte array. but for the hexadecimal values like 8, d, 11, 0, e4 when parsing i m getting wrong value for e4 as -28 instead of 228. how can i overcome this conversion error....
FileInputStream fstream = new FileInputStream("C:/Users/data.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(newInputStreamReader(in,"UTF-8"));
byte[] bytes = new byte[1024];
String str;
int i=0;
while ((str = br.readLine()) != null)
{
bytes[i]= (byte) (Integer.parseInt(str,16) & 0xFF);
i++;
}
byte[] destination = new byte[i];
System.arraycopy(bytes, 0, destination, 0, i);
br.close();
return destination;
[-128, 127], the value after127goes to the negative side. And hence228is-28.