hello again,
i am having problems outputing the correct format of hex, the result i am aiming to achieve in my file should be :
78 00 07 D0 00 00 17 70 00 00 <-- aiming to achieve
D8 00 6F D0 00 00 7F F0 00 <-- actual output
The problem is i am trying to convert the values 16000 and 12000 that are int's into strings and output them as a single byte stream to achieve it.
RECT(int x, int y) {
// set defaults
Xmax = x;
Ymax = y;
Xmin = 0;
Ymin = 0;
}
String GETRECTANGLE() {
// get total number of binary bits
int binSize = Xmin + Xmax + Ymin + Ymax;
String bins = Integer.toBinaryString(binSize);
binSize = bins.length(); // stores the number of bits needed
String output = padOut(Integer.toBinaryString(binSize),
Integer.toBinaryString(binSize).length()+1)//+1 later
.concat(padOut(Integer.toBinaryString(Xmin), binSize))
.concat(padOut(Integer.toBinaryString(Xmax), binSize))
.concat(padOut(Integer.toBinaryString(Ymin), binSize))
.concat(padOut(Integer.toBinaryString(Ymax), binSize));
//add all values into one string, padding each binary number to the size of largest number
return output;
}
/*implementation of writing below*/
RECT b = new RECT(16000, 12000);
//write out the string as a series of 8 bits
for (int i = 0; i < b.GETRECTANGLE().length(); i = i + 8) {
if (i + 8 < b.GETRECTANGLE().length()) {
String output = b.GETRECTANGLE().substring(i, i + 8);
int value = Integer.parseInt(output);
out2.write((byte) value);
}
if (i + 8 > b.GETRECTANGLE().length()) {
int j = i + 8 - b.GETRECTANGLE().length();
String output = b.padOut(
b.GETRECTANGLE().substring(i, i + 8 - j), 8);
int value = Integer.parseInt(output);
out2.write((byte) value);
}
Any help on finding why it outputs incorrectly would be fantastic :)