根据您提供的问答内容,我为您提供了以下完善且全面的答案:
将int转换为unsigned short Java 的方法:
int num = 123;
short unsignedShort = num == Integer.MIN_VALUE ? (short) 0 : (short) Integer.toUnsignedShort(num);
int num = 123;
short unsignedShort = (short) (num & 0xFFFF);
int num = 123;
short unsignedShort = (short) (num | 0x1000);
int num = 123;
short unsignedShort = (short) (num & 0xFFFF);
if (num > 0xFFFF) {
unsignedShort = (short) (num | 0x1000);
}
int num = 123;
if (num > 0xFFFF) {
short unsignedShort = (short) (num | 0x1000);
} else {
short unsignedShort = (short) (num & 0xFFFF);
}
希望这个答案能够帮助您!
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云