Shop OBEX P1 Docs P2 Docs Learn Events
* How do I flip bit#n in a word variable? — Parallax Forums

* How do I flip bit#n in a word variable?

youngdaveyoungdave Posts: 70
edited 2009-08-27 06:12 in Propeller 1
Dear All
* How do I flip bit#n in a word variable?
TIA David Young

Comments

  • BradCBradC Posts: 2,601
    edited 2009-08-26 06:40
    "word ^= 1 << bit" should do the trick.
    1 << bit makes a 1 bit mask from the bit number you want and it's then XOR'd against your word variable to invert only that specific bit

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lt's not particularly silly, is it?
  • youngdaveyoungdave Posts: 70
    edited 2009-08-26 07:16
    Thanks. I turned into this.
    term.bin(Chromosome[noparse][[/noparse]Current_Population_Size] ^= 1 << (|| rr.random // 16+1),16)
    David Young
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-26 14:54
    Dave,

    Your variable names intrigue me. Are you writing a GA for the Prop?

    BTW, you can copy and paste your code here, www.phipi.com/format, to convert it to something that displays better in the forum.

    -Phil
  • youngdaveyoungdave Posts: 70
    edited 2009-08-26 19:10
    It's a GA controller to stabilize the motion of AUV (in the very early stages).
    TIA David Young
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-26 20:15
    Dave,

    The fact that you're matching bit strings leads me to infer that you're using a Michigan (John Holland)-style learning classifier system. Correct?

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 8/27/2009 2:31:26 AM GMT
  • youngdaveyoungdave Posts: 70
    edited 2009-08-27 02:10
    Phil
    Who's John Holland?
    TIA David Young
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-27 02:33
    John Holland is the guy who invented genetic algorithms: en.wikipedia.org/wiki/John_Henry_Holland. Here's an intro to learning classifier systems: www2.cs.uh.edu/~ceick/6367/bull-lcs.pdf.

    -Phil
  • youngdaveyoungdave Posts: 70
    edited 2009-08-27 06:12
    Phil
    Don't want to be too picky here, but Holland simply reinvented genetic algorithms based on the real thing!
    Thanks for the PDF. I try to avoid that type of stuff because its not in my language, and I end up confused, rather than than thinking it thru from first principles. But thanks, I'll have a look at it.
    TIA David Young
Sign In or Register to comment.