我有一个整数
int a = //...
java 中的 int
由 4 个字节组成。如果我们将它转换为 short
,我们将占用两个最低有效字节。获得 short
的最快方法是什么,其中包含 int
的 2 个最重要的 byte
?
short b = //take two most significant bytes of a
最佳答案
short b = (short) (a >> 16);
关于java - int to short 两个最高有效字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45650436/