mask « bit « Java Data Type Q&A

1. create a permission bit mask in java

I want to do something like this:

public enum Permissions

byte[] userPerm = Permissions.CanBlah1 | Permissions.CanBlah2;

// check permssions
if(userPerm && Permissions.CanBlah1 == ...

2. How to avoid sign extending bit mask in Java?

My bit masks are bytes, and I'd like to keep them exactly as they are, but I think they're sign extended. I don't care if the byte is considered positive ...

3. bit mask

4. problem with mask and bitwise manipulator

I am building a method that needs to: Assign to a local variable named mask the value 1 shifted left 31 times. This puts a 1 in bit 31 and zeros in all other bits. Use a for loop to step through all 32 bits, doing the following in each step: o Use a conditional operator whose condition is (mask & ...

5. Bit masking question

I have a question related to bit masking. Just making sure I am doing this the right way. I have a 6 byte number stored in a long. The idea is to extract the first byte and check to see if the number matches 47. This is how I wrote the code: int s = (6-byte-number & 0xf00000) >> (2 ^ ...