How to decrement?

  • resic
    13th January Member 0 Permalink

    I already know how to increment a number in one frame (id:2447121) but how do I decrement it? This question is too specific for TPT, that's why I'm struggling to find the answer on the internet.

  • LBPHacker
    13th January Developer 1 Permalink
    Negate the bits of both the input and the output.
  • resic
    13th January Member 0 Permalink

    that indeed worked, thanks!

  • Jerehmia
    15th January Member 0 Permalink

    The incrementer is based on a fast two's complement algorithm (which computes the negative of a number). If you delete the FILT(s) in NOT mode what you're left with is the two's complement algorithm.

     

    Because a two's complement algorithm is functionally equvalent to "flipping the input bits + 1" you can easily turn it into an incrementor or decrementor: if you invert the intput you undo the implicit bit flip so what you're left with is the "input + 1" part and you have an incrementor, and if you invert the output you effectively compute "-(-input + 1)" which is equivalent to "input - 1" so you end up with a decrementor.