What does the “&=” in this C# code do?

It’s not a bitwise operator when it’s applied to boolean operators. It’s the same as: someBoolean = someBoolean & someString.ToUpperInvariant().Equals(“blah”); You usually see the short-cut and operator &&, but the operator & is also an and operator when applied to booleans, only it doesn’t do the short-cut bit. You can use the && operator instead … Read more

How is this bitwise AND operator masking the lower seven order bits of the number?

The number 0177 is an octal number representing the binary pattern below: 0000000001111111 When you AND it using the bitwise operation &, the result keeps the bits of the original only in the bits that are set to 1 in the “mask”; all other bits become zero. This is because “AND” follows this rule: X … Read more

Why in Java (high + low) / 2 is wrong but (high + low) >>> 1 is not?

In short, (high + low) >>> 1 is a trick that uses the unused sign-bit to perform a correct average of non-negative numbers. Under the assumption that high and low are both non-negative, we know for sure that the upper-most bit (the sign-bit) is zero. So both high and low are in fact 31-bit integers. … Read more

Why does bitwise “not 1” equal -2?

There are 2 integers between 1 and -2: 0 and -1 1   in binary is 00000000000000000000000000000001 0   in binary is 00000000000000000000000000000000 -1 in binary is 11111111111111111111111111111111 -2 in binary is 11111111111111111111111111111110 (“binary” being 2’s complement, in the case of a bitwise not ~ ) As you can see, it’s not very surprising ~1 equals -2, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)