ML:
>I didn't talked about GUI, what do you mean? I'm trying to program a
>communication driver for a Serial Port with a special Protocol (3964R),
>nothing else.
Right now, you are posting into a GUI newsgroup.
<news:comp.lang.java.programmer> or <news:comp.lang.java.help> would
be more appropriate. Or try the German language newsgroup
<news:de.comp.lang.java>, but people there are more into formalities
like using the real name instead of initials, quoting correctly
<http://www.afaik.de/usenet/faq/zitieren/> etc.
Anyway, why do you need Byte objects instead of primitive byte values
as you say in your reply to Roedy?
I'm still unsure where the problem lies, so I'll just mention some
things potentially helpful.
You can xor two values using the ^ operator. Restrict the result by
ANDing it with 1. Example:
int i1 = 0;
int i2 = 1;
int result = (i1 ^ i2) & 1;
Conversion from int to byte:
byte b = (byte)result;
You can create a new BitSet object, set some bits with the set method
and call xor(BitSet) on it. Check out the API docs for details.
Conversion Byte to byte: a call to Byte#byteValue().
Byte b1 = ...;
byte b2 = b1.byteValue();
Conversion byte to Byte: create a new object with the
constructorByte(byte).
byte b1 = ...;
Byte b2 = new Byte(b1);
If that all doesn't solve the problem, please post your algorithm code
(what you got so far) here (or preferably in one of the other Java
newsgroups) and the compiler messages, maybe we can go from there.
Regards,
Marco

Signature
Please reply in the newsgroup, not by email!
Java programming tips: http://jiu.sourceforge.net/javatips.html
Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html
Roedy Green - 31 Oct 2003 08:25 GMT
>Anyway, why do you need Byte objects instead of primitive byte values
>as you say in your reply to Roedy?
To compute the xor of an array of bytes
int result = 0;
for ( int i=0; i<20; i++ )
{
result ^= bytes[i];
}
// chop high order bits
byte byteresult = (byte) result;
If you really must work with an array of Byte objects, do it like
this:
int result = 0;
for ( int i=0; i<20; i++ )
{
result ^= bytes[i].byteValue();
}
// chop high order bits
byte byteresult = (byte) result;
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
> I didn't talked about GUI, what do you mean? I'm trying to program a
> communication driver for a Serial Port with a special Protocol (3964R),
> nothing else.
So, why do you post to a GUI news group?
Beginners questions should go to comp.lang.java.help. Non-GUI API
questions to comp.lang.java.programmer. Followup-To set.
Regarding your question: It is not clear what you want. You keep
talking about a conversion problem, but you fail to tell us what this
problem might be. And no, "Byte[] bytes = new Byte[20];" is not a
conversion problem. It is a valid java statement, and does exactly what
it is supposed to do. As others have pointed out, you most likely want
byte, not Byte.
/Thomas