Shop OBEX P1 Docs P2 Docs Learn Events
Spin question - bitwise and operator — Parallax Forums

Spin question - bitwise and operator

vyper4vyper4 Posts: 7
edited 2012-02-19 01:28 in Propeller 1
Ok, I am brand new to all of this, so forgive me if this is an overly simple question.

I downloaded and I am reading through the Stingray Ping Demo code and I came across this operation.
Pwm.duty(base_pin + 2, speed & $FF)

Speed is variable with the range -255 to 255, what does the & $FF do?

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2012-02-19 01:28
    Hello and welcome to the propeller-forum.

    in the hex-number $FF bit 0 up to bit 7 is set to one. All other bits (bit8-31) are zero.
    The bitwise and-operator "&" used with value $FF=binary %11111111 sets all bits above bit 7 to zero.

    If this is clear to you and you want to know WHY the code does this please change the thread-title to words that ask directly the why.

    keep the questions coming
    best regards
    Stefan
Sign In or Register to comment.