Tag: 位掩码

为按位操作声明掩码

我是这样的低级别操作的新手,我希望有人可以指出我必须在这里犯下的明显错误。 //Input value – 00111100 //I want to get the value of the bits at indexes 1-3 ie 0111. byte mask = (byte)0x00001111; // This gives 17 not the 15 I’d expect byte shifted = (byte)(headerByte >> 3); //shifted is 7 as expected byte frameSizeValue = (byte)(shifted & mask); //Gives 1 not 7 看起来问题在于定义掩码的方式,但我看不出如何修复它。

位掩码问题?

我有以下内容: public static final int LIMIT_ONE = 1; public static final int TRADEABLE = (1 << 1); public static final int SELLABLE = (1 << 2); public static final int STORABLE = (1 << 3); public static final int STORABLE_IN_WH = (1 << 4); public static final int STORABLE_IN_LEGION_WH = (1 << 5); public static […]

在java中创建权限位掩码

我想做这样的事情: public enum Permissions { CanBlah1, CanBlah2, CanBlah3 } byte[] userPerm = Permissions.CanBlah1 | Permissions.CanBlah2; // check permssions // if(userPerm && Permissions.CanBlah1 == Permissions.CanBlah1) { // do something } 你能用Java做到这一点吗? (我来自ac#背景)