• 15 Posts
  • 258 Comments
Joined 2 years ago
cake
Cake day: July 23rd, 2023

help-circle

  • But what is an example of where I can use it?

    Aside from operations on bitfields, a bitwise operator can be useful in several “non bits” cases. For instance:

    value & 1 evaluates to 1 if value is odd (and will evaluate to True in an if statement)
    value >> 1 divides value by 2 (integer division)

    But usually bitwise operators are for when you want to manipulate bits in values. For instance:

    value | 5 returns value with bits 1 and 3 set to True
    value & 0xffff returns the 16 least-significant bits in value (usually you do this to make sure it will fit in 2 bytes in memory for example)
    value & (0xffff ^ 5) returns the lower 16 bits of value with bits 1 and 3 set to False

    Etc.


  • Much to unpack here…

    coin == 25 | 10 | 5

    …will evaluate as True if coin is equal to the bitwise OR of 25, 10 and 5 - i.e. 31. In other word, it’s equivalent to coin == 31. That’s because the bitwise OR has precedence over the == operator. See operator precedence in Python.

    If I replace the ‘|’ with ‘or’ the code runs just fine.

    It probably doesn’t. If you replace | with or, you have the statement coin == 25 or 10 or 5 which is always True in the if statement because it’s evaluated as (coin == 25) or (not 0) or (not 0) in an if statement.

    coin == 25 | coin == 10 | coin == 5

    …will evaluate as coin == (25 | coin) == (10 | coin) == 5. Again, operator precedence.

    What you want to do is this:

    if coin in [25, 10, 5]:

    or

    if coin in (25, 10, 5):

    or simply

    if coin == 25 or coin == 10 or coin == 5:

    Don’t create problems and confusion for the next guy who reads your code for nothing. Simple and readable are your friends 🙂















  • I use Terminator. It’s nothing fancy but it works fine.

    If I work locally, I usually stick several Terminator windows side-by-side and up-and-down in i3 tiles and that’s good enough.

    If I work remotely through SSH though - which is 75% of what I do in a terminal, I’ll run tmux so I can have several shells in one terminal of course, but mostly so that I don’t lose what I’m doing if the internet goes down.






  • Isn’t it the same as tuning?

    Although it’s unclear what tuning is because it depends on who says it:

    • It does mean doing modifications to a vehicle for actual performance improvements
    • It’s used extensively by ricers to describe themselves and their hobby and they think it’s a positive term
    • It’s used extensively by people who dislike ricing and most definitely as a derogatory term

    Yet for all its faults, I believe that’s the closest word to ricing you’ll find that is universally understood, neutral and isn’t rendered hopelessly bland and meaningless by the process of political correctness newspeak.