Decode value |< "value" — Parallax Forums

# Decode value |< "value"

Posts: 82

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) ?

• Posts: 3,442
edited 2022-06-11 15:31

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 as `ifnot value&31`, but I guess that's just your example nonsense.

• Posts: 8,458
edited 2022-06-11 17:14

Ada is correct. Think of the `|< x` as `1 << (x & \$1F)` A bit of test code proves that.

• Posts: 3,442

@JonnyMac said:
Ada is correct. Think of the `|< x` as `1 << (x // 32)`. A bit of test code proves that.

Well, really just `1 << x`, since the shift operators have the same wraparound behaviour

• Posts: 8,458

I just noticed that, which was was a surprise. I had always that believed that shifting with a value > 31 resulted in 0.

• Posts: 23,514

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

• Posts: 82
edited 2022-06-12 08:25

Thanks everybody 😊

Perhaps the manual should have added this information?