my purpose to read from stream as byte per digit do some logic and write back to binary file
Lets say the representation of data is 0F000200 17000000 07003B00
so we have method to represent it
InputStream stream = new FileInputStream(args[0]);
private static int readShort(InputStream stream) throws IOException {
return stream.read() + stream.read() * 10;
}
// ***** when we read the results ******
int day = readShort(stream); // => 15
int month = readShort(stream); // => 2
int year_suffix = readShort(stream); // => 23
int hour = readShort(stream); // => 0
int minute = readShort(stream); // => 7
int second = readShort(stream); // => 59
Now I want to write it back as byte array so I did:
FileOutputStream stream = new FileOutputStream("/path/to/file");
writeShort(stream, day);
writeShort(stream, month);
writeShort(stream, year);
writeShort(stream, hour);
writeShort(stream, minute);
writeShort(stream, second);
private static void writeShort(OutputStream stream, int value) throws IOException {
stream.write(value % 10);
stream.write(value / 10);
}
But when I look into output file I see the header is not the same
the value are 05010200 03020000 07000905
instead of 0F000200 17000000 07003B00
please suggest ( picture from Hex fiend editor)