I am getting unexpected results (likely due to my misuse or misunderstanding of how a bitwise (&) expression is supposed to work). I have the following code:
string sbin = "10010110"; // 150 = 1001 0110
uint ival = Convert.ToUInt32(sbin, 2);
ival.Dump(); // 150 Expected Correct
uint lval = ival << 16; // Shift 16 bits left
lval.Dump(); // 9830400 - Expected Correct
string slval = Convert.ToString(lval, 2);
slval.Dump(); // 0000 0000 1001 0110 0000 0000 0000 0000 - Expected Correct
uint lrval = lval & ival; // <--- This is where I am confused (while a '+' operator works, why does the & not return the proper result?)
// expecting 0000 0000 1001 0110 0000 0000 1001 0110 (aka 9830550 (dec))
lrval.Dump(); // returns 0,
I am looking for an explanation as to where my logic is failing. My end expression I am looking to accomplish is:
uint xpos = 150;
uint ypos = 150;
uint val = ((xpos) & ((ypos) << 16))); // result is 0, should be 9830550 as above)
Of course
((xpos) + ((ypos) << 16))); // Would work properly
However all examples I have seen (for purposes of mouse position (POINT) locations all have shown '&' in the expression)