Speed up bitstring/bit operations in Python?

There are a couple of small optimizations for your version. By reversing the roles of True and False, you can change “if flags[i] is False:” to “if flags[i]:“. And the starting value for the second range statement can be i*i instead of i*3. Your original version takes 0.166 seconds on my system. With those changes, … Read more

Bitwise XOR of hexadecimal numbers

Whoa. You’re really over-complicating it by a very long distance. Try: >>> print(hex(0x12ef ^ 0xabcd)) 0xb922 You seem to be ignoring these handy facts, at least: Python has native support for hexadecimal integer literals, with the 0x prefix. “Hexadecimal” is just a presentation detail; the arithmetic is done in binary, and then the result is … Read more

(x | y) – y why can’t it simply be x or even `x | 0`

The code is found in _spin_lock_contested, which is called from _spin_lock_quick when someone else is attempting to obtain the lock : count = atomic_fetchadd_int(&spin->counta, 1); if (__predict_false(count != 0)) { _spin_lock_contested(spin, ident, count); } If there’s no contest, then count (the previous value) should be 0, but it isn’t. This count value is passed as … Read more

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