Spin question - bitwise and operator
vyper4
Posts: 7
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.
Speed is variable with the range -255 to 255, what does the & $FF do?
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
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