[英]JAVA: [-255…255] int to 2 bytes array
I have an integer that can only contains values between - 255 and 255. I know that it can be represented with 2 bytes (I'm right?) How can I convert this int to 2 bytes array? 我有一个只能包含-255和255之间的值的整数。我知道它可以用2个字节表示(我是对的吗?)如何将该int转换为2个字节的数组? Many thanks 非常感谢
Rather than store in two distinct bytes and implement your own custom encoding and decoding, it would be easiest to store these values in a short
. 与其存储两个不同的字节并实现自己的自定义编码和解码,不如将它们存储在short
,将是最简单的。 This is a 16 bit signed integer with sufficient range for your values. 这是一个16位有符号整数,具有足以容纳您的值的范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.