• Iron Lynx
    link
    fedilink
    132 years ago

    Even the shitposty better version has us:

    • take the absolute value of the input as a variable
    • while that variable is >1, subtract 2. Repeat until this is no longer true
    • if it’s now 1, return true. Otherwise, return false.
    • Iron Lynx
      link
      fedilink
      1
      edit-2
      2 years ago

      On a sidenote, the completely non-shitposty version would be:

      return !(var & 1);

      Notice the single &, which should be bitwise AND. Fun thing: negative numbers in two’s complement also have 1 for their LSB when odd. C definitely supports bitwise operators, and it appears C# does as well.