我有一个二进制数,看起来像这样:
00000000 00000000 00000011 00001101 = 781整数值=整数名称"已打包"
如何在java中使用bit wise提取每个值作为单独的整数值.如下:
int a = (function) = 00000000;
int b = (function) = 00000000;
int c = (function) = 00000011;
int d = (function) = 00001101;
Run Code Online (Sandbox Code Playgroud)
如果你能看到我在那里做什么..我希望前8个成一个整数,然后下一个整数,依此类推......我认为你在java中使用有点明智但我完全不确定.任何帮助表示赞赏.对不起,但我对这种事情全新,真的需要帮助,谢谢!基本上(函数)应该像这样:
packed >> 5; (I know this isn't nearly right that is why i am needing help on this)...
Run Code Online (Sandbox Code Playgroud)
这个问题在2天前得到了回答,它工作得非常好,但现在它已经破了......我不知道为什么......这里是我用来做这个的方法:
public static int getNthByte(int n, int packed)
{
// shift the desired bits into the last 8 bits
int shifted = packed >> (8 * n);
// …Run Code Online (Sandbox Code Playgroud)