java中整数默认都是有符号类型的,在进行第三方库或者c/c++调用时有时候需要无符号类型。
比如海康威视SDK调用
常见的无符号类型 unsigned int, unsigned char, unsigned short, unsigned byte, unsigned long.
以下介绍一个三方库jOOU, github地址 https://github.com/jOOQ/jOOU,他能支持 unsigned byte/short/int/long不过不支持char。
java是unicode字符集,utf-8编码,char默认应是双字节的。
官方介绍:
jOOU - Unsigned Integers jOOU provides unsigned integer versions for the four Java integer types byte, short, int and long.
用法:(java6-8)
<dependency> <groupId>org.jooq</groupId> <artifactId>joou-java-6</artifactId> <version>0.9.4</version> </dependency>
there is a utility class called org.joou.Unsigned
with factory methods allowing for creating unsigned wrappers like this:
import static org.joou.Unsigned.*; // and then... UByte b = ubyte(1); UShort s = ushort(1); UInteger i = uint(1); ULong l = ulong(1);
其他支持无符号类型的库Guava
Generic utilities
These methods' signed analogues are provided in the wrapper classes in the JDK.
UnsignedLongs, UnsignedLong, UnsignedBytes, UnsignedInteger, UnsignedInts,
本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。