Is there any sense in performing binary AND with a number where all bits are set to 1
        Posted  
        
            by n535
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by n535
        
        
        
        Published on 2010-03-27T12:38:03Z
        Indexed on 
            2010/03/27
            12:53 UTC
        
        
        Read the original article
        Hit count: 354
        
Greetings everybody. I have seen examples of such operations for so many times that I begin to think that I am getting something wrong with binary arithmetic. Is there any sense to perform the following:
byte value = someAnotherByteValue & 0xFF;
I don't really understand this, because it does not change anything anyway. Thanks for help.
P.S. I was trying to search for information both elsewhere and here, but unsuccessfully.
EDIT: Well, off course i assume that someAnotherByteValue is 8 bits long, the problem is that i don't get why so many people ( i mean professionals ) use such things in their code. For example in Jon Skeet's MiscUtil there is:
uint s1 = (uint)(initial & 0xffff);
where initial is int.
© Stack Overflow or respective owner