문제

I'm looking for something that does the same thing than outputStream.write() but which will accept an array of int.

Actually, I'm using this one : outputStream.write() but this one accepts only byte,byte[] or int.

I could use the byte[] but the values I want to send are

 [255,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255]

so I can use the byte[] because there range are only from -127 to 127 :/

It's to send a command on a Port_Com which accept only packet of 19 bytes and must be start and end with 255.

도움이 되었습니까?

해결책

This is a common misconception about bytes, because of rumors repeated again and again.

Actually, the range of byte is from

00000000 (binary) to   11111111 (binary)

There is no reason to interpret bytes as numbers, if you're only interested in the bit patterns. There is, in particular, no reason to interpret bytes as signed numbers, just because java does it that way by default.

Hence, go ahead, as Jon Skeet says, cast your integers to byte and write those bytes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top