Skip to content

rev [terminology]

Terminology

Usage

  • Use for a reversed representation being constructed.
  • It is more semantic than ans in reversal algorithms.
  • It can represent reversed digits, bits, characters, or links when the context is clear.
rev = 0
for _ in range(32):
    rev <<= 1    # Make room for the next bit.
    rev |= n & 1 # Append n's current last bit.
    n >>= 1      # Move to the next bit in n.

See 190. Reverse Bits.