Decode value |< "value"
MAElektronik
Posts: 96
in Propeller 1
A simple question using bitwise decode operator.
Example code:
If |<value & % 0000_0001
"Do something"
else
"Do something else"
What happens if value is outside 0 to 31 ?
What if value == TRUE (-1 decimal) ?
Comments
I'm decently sure it just wraps around. I.e.
|<x == |<(x&31)
. So|<(-1) == |<31 == $8000_0000
.Note that
If |<value & %0000_0001
could just be written asifnot value&31
, but I guess that's just your example nonsense.Ada is correct. Think of the
|< x
as1 << (x & $1F)
A bit of test code proves that.Well, really just
1 << x
, since the shift operators have the same wraparound behaviourI just noticed that, which was was a surprise. I had always that believed that shifting with a value > 31 resulted in 0.
As I understand it, the Propeller uses a "barrel shifter", so nothing really get "shifted." It's just a fancy set of multiplexers that take part of the input and gate it somewhere else into the result. The multiplexers themselves are gated by a decoder, whose inputs are the lower five bits of the shift amount.
-Phil
Thanks everybody 😊
Perhaps the manual should have added this information?