• Einar@lemm.ee
    link
    fedilink
    arrow-up
    11
    arrow-down
    4
    ·
    edit-2
    1 year ago

    Recently there was a thread trying to declare PHP obsolete.

    Hard to beat this in efficiency:

    function is_even($num) {
        return $num % 2 === 0;
    }
    
    

    That said, this should work similarly in most languages.

    • jmcs@discuss.tchncs.de
      link
      fedilink
      arrow-up
      5
      ·
      1 year ago

      If the language you are using uses “real” integers, using a bit mask to get the least significant bit is probably a lot faster - assuming the compiler doesn’t replace the operation for you, in which case it doesn’t matter.