Shop OBEX P1 Docs P2 Docs Learn Events
Reversing (mirroring) copy of a specified number of bits — Parallax Forums

Reversing (mirroring) copy of a specified number of bits

Chuck H-MChuck H-M Posts: 1
edited 2007-06-18 20:15 in BASIC Stamp
In my old Basic Stamp Manual, Version 1.9. On·pgs 239 & 245 there is a REV command, which will supposedly do this.· If my variable word is "wordout", and I want to reverse only the last 12 bits, how do I use the REV command?

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-06-18 19:44
    Do a 'REV' then shift the result right (down) 4 bits.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-06-18 20:15
    By "last 12 bits" do you mean the least or most significant bits?

    x = %0110111011110001
    DEBUG CR,BIN (x REV 12) ' prints 100011110111 reversal of 12 lsbs
    DEBUG CR,BIN12 (x REV 16) ' prints 111101110110 reversal of 12 msbs

    Note that REV is a binary operator. There are other combinations you might want, for example, to reverse the 12 least significant bits but keep the 4 msbs the same:

    DEBUG CR,BIN16 (x REV 12) | (x & $F000)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.