1

I'm trying to implement the following pseudocode:

enter image description here

But I fail to understand what the line

state_val |= (c(s) == True) << i++

does. To give some context, this pseudocode is found in this paper from MIT, and c(s) is an operation that returns True or False based on s.

Thomas Wagenaar
  • 6,489
  • 5
  • 30
  • 73
  • Does this answer your question? [What does "|=" mean? (pipe equal operator)](https://stackoverflow.com/questions/14295469/what-does-mean-pipe-equal-operator) – Reine_Ran_ Mar 28 '20 at 14:59

2 Answers2

3

a |= b means that a will be set to the bitwise OR of a and b. Essentially, state_val is a number whose bits represent booleans, and its binary representation will look something like this:

c7(s) c6(s) c5(s) c4(s) c3(s) c2(s) c1(s) c0(s)

Where c0 is the first c, c1 is the second, etc. If c7(s), c5(s), and c1(s) were true, then state_val would be 10100010 in binary or 162.

Aplet123
  • 33,825
  • 1
  • 29
  • 55
1

It's bitwise OR. Basically shorthand for

state_val = state_val | ((c(s) == True) << i++)
bottaio
  • 4,963
  • 3
  • 19
  • 43