• 10 Posts
  • 46 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 🙂




  • Abuse is going to happen In any organization that works with children

    Abuse is going to be 10x worse in organizations that specialize in brainwashing and bigotry, emphasize hierarchy and cultivate secrecy.

    That’s why, while you’re correct, child abuse cases almost always come from cults (including the widely recognized cults we coyly call churches), sketchy historical children indoctrination outfits like the Scouts, much less often from schools, and rarely from pediatricians and other medical professionals.


  • Aah, traditions… Joseph Smith and Bring’em Young would be proud.

    For what it’s worth, here’s the list of teenage brides of those two holy pedos:

    • Teen Brides of Joseph Smith Jr.:

    Fanny Alger—16 (JSJ—27 ) Sarah Ann Whitney—17 (JSJ—36 ) Flora Ann Woodworth—16 (JSJ—37 ) Emily Dow Partridge—19 (JSJ—37 Lucy Walker—17 (JSJ—37 ) Sarah Lawrence—17 (JSJ—37 ) Maria Lawrence—19 (JSJ—37 ) Helen Mar Kimball—14 (JSJ—37 ) Melissa Lott—19 (JSJ—37 ) Nancy Mariah Winchester—14 (JSJ—37 )

    • Teen Brides of Brigham Young:

    Miriam Angeline Works—18 (BY—23 ) Harriet Elizabeth Cook —19 (BY—42 ) Clarissa Caroline Decker —15 (BY—42 ) Elizabeth Fairchild —16 (BY—43 ) Diana Chase —17 (BY—43 ) Emmeline Free —18 (BY—43 ) Ellen Rockwood —16 (BY—44 ) Mary Ann Turley —18 (BY—44 ) Lucy Bigelow —16 (BY—45 ) Mary Jane Bigelow —19 (BY—45 )







  • I’m curious about cola:

    In all the countries I’ve lived in, I’ve always bought store-brand colas - mostly to avoid giving any of my money to Pepsi and Coca-Cola, but also because they’re usually a lot cheaper. Most store-brand colas were denominated in the local language.

    I always assumed they were made locally because… well, cola is just water with sugar really. But are they? I doubt Cola from Aldi in Germany or K-Market in Finland are made in China or the US, but in fact I don’t know. Does anybody know?