Shop OBEX P1 Docs P2 Docs Learn Events
Decode value |< "value" — Parallax Forums

Decode value |< "value"

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

  • Wuerfel_21Wuerfel_21 Posts: 4,449
    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.

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

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

  • @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

  • I 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

  • MAElektronikMAElektronik Posts: 94
    edited 2022-06-12 08:25

    Thanks everybody 😊

    Perhaps the manual should have added this information?

Sign In or Register to comment.