I am developing an RFID reader application using Java. The RFID reader's message type has to start with 0xA0. It is obligatory. It is represented as 160 in decimal form. But in java byte values can not be greater than 127.
How do I solve this?
Just send (byte) 0xa0
. Yes, as a Java byte
it will be negative, but it will still have the right bit pattern, which is all the RFID will care about.
Basically, you rarely need to think of bytes as numbers as such - it's more usual to think of them as sequences of bits, which happen to map to numbers.
For example, suppose you have a file consisting of a single byte, with the bits 11111111
. If you read the data for that in Java, you'll get a byte of -1. If you read the data for that in C#, you'll get a byte of 255. It's the same data, just viewed in a slightly different way.
See more on this question at Stackoverflow