I need to send some commands to my microcontroller. Iam using the RXTX library. I can connect to my microcontroller but i have problems to convert my commands to right bytes.
example: i want to send 0x80 hex value.
if i convert 128 integer (0x80) to bytes
byte a = (byte) 128;
i get -128
the range from java bytes is -128 - 127
but i need to send 128 as a command. How can i convert it?
also i do have other commands to send.
80
20 F2 40 F8 3F
FA 21 40
one of them is 40 bits.
I write to the outputstream, that can accept byte[]
or int
.
...
static OutputStream out;
out.write(byte[]);
out.write(int);
..
But int is out of range with 40bit. How can i parse a 40bit Integer to a byte?