outputStream.write()对于int []数组 [英] outputStream.write() for int[] array

查看:436
本文介绍了outputStream.write()对于int []数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找东西做比 outputStream.write同样的事情(),但将接受一个int数组。

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

其实,我用这一个: outputStream.write()但是这一次只接受字节字节[] 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]

这样我就可以使用字节[] ,因为有范围只是从 -127到127 :/

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

这是对一个Port_Com其只接受19字节的数据包,必须开始和结束255发送一个命令。

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)

有没有理由间preT字节数,如果你只在位模式感兴趣。在那里,是特别,没有理由间preT字节的签署的数字,只是因为Java在默认情况下不这么认为。

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.

这篇关于outputStream.write()对于int []数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆