After testing iago's binary packet buffer he wrote for his Javabot, it became apparent that adding bytes with high values seemed to be impossible so I ran some quick tests only to discover this error
*** Semantic Error: A byte value must be an integer value in the range of -128..127
NOTE: I achieved this error from just compiling a primitive byte with a value of 255.
From my understanding this means we'd never be able to add a byte with a decimal value higher than 127. This would make adding 0xff for example, impossible. Any thoughts on this problem?
Hmm, I think a simple change can fix that. Just store it as an integer or long until it gets put into a byte, then mask it to put it into the byte.
Quote from: Orillion on December 01, 2003, 12:55 AM
After testing iago's binary packet buffer he wrote for his Javabot, it became apparent that adding bytes with high values seemed to be impossible so I ran some quick tests only to discover this error
*** Semantic Error: A byte value must be an integer value in the range of -128..127
NOTE: I achieved this error from just compiling a primitive byte with a value of 255.
From my understanding this means we'd never be able to add a byte with a decimal value higher than 127. This would make adding 0xff for example, impossible. Any thoughts on this problem?
why wouldn't 0xff work? in a signed variable 0xff = -128 am I wrong?
Quote from: Etheran on December 01, 2003, 04:48 PM
Quote from: Orillion on December 01, 2003, 12:55 AM
After testing iago's binary packet buffer he wrote for his Javabot, it became apparent that adding bytes with high values seemed to be impossible so I ran some quick tests only to discover this error
*** Semantic Error: A byte value must be an integer value in the range of -128..127
NOTE: I achieved this error from just compiling a primitive byte with a value of 255.
From my understanding this means we'd never be able to add a byte with a decimal value higher than 127. This would make adding 0xff for example, impossible. Any thoughts on this problem?
why wouldn't 0xff work? in a signed variable 0xff = -128 am I wrong?
I think the problem they are speaking of is having to use signed constants (this being inconvenient and a pain).
Quote from: Etheran on December 01, 2003, 04:48 PMin a signed variable 0xff = -128 am I wrong?
Yes. 0xff = 255 = -1.
Quote from: Kp on December 01, 2003, 05:54 PM
Quote from: Etheran on December 01, 2003, 04:48 PMin a signed variable 0xff = -128 am I wrong?
Yes. 0xff = 255 = -1.
err yes of course, that would be 0x80 = -128 and 0x7F = 127
Yeah the problem i think stems from the fact that java automatically signs everything. Although we have gotten around that to a certain extent
Er, sort of off topic, what part of '0x80' determines that it's negative 128?
The sign bit, or the first bit in the number.
Quote from: St0rm.iD on December 08, 2003, 08:15 AM
The sign bit, or the first bit in the number.
Technically, it's the last bit. I would call it the left-most bit :)
Yes, left-most.
and to find your signed value if the sign bit is set, you take the two's complement of the number:
~x + 1
example:
1101 1001 = 0xC9
take the two's complement:
0010 0110 + 1 = 0010 0111 = 39
add the sign and you end up with -39
hmm, I don't see what your problem was. I just tested it out with the following code:
public static void main(String args[])
{
Buffer buf = new Buffer();
buf.add((byte)250);
buf.add((byte)251);
buf.add((byte)252);
buf.add((byte)253);
buf.add((byte)254);
buf.add((byte)255);
buf.add((byte)-1);
buf.add((byte)-2);
buf.add((byte)-3);
buf.add((byte)-4);
buf.add((byte)-5);
System.out.println(buf.toText());
}
And it came back with the (correct) results:
Buffer contents:
fa fb fc fd fe ff ff fe fd fc fb ...........
Length: 11