Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you have mask-based enums, you check whether that enum is satisfied or not using the bit-wise AND operator <code>&amp;</code>.</p> <p>So, if you want to check if the skills are fast AND smart, do it like so:</p> <pre><code>if ((skills &amp; fast) &amp;&amp; (skills &amp; smart)) { // this team has the brains and speed.. possible other stuff } </code></pre> <p>Alternatively, in this situation, the XOR operator would also be a good candidate:</p> <pre><code>if (skills ^ (fast | smart) == 0) { // this team has ONLY the brains and speed. } </code></pre> <p>Last Note:</p> <p>Define the enums like this, much easier:</p> <pre><code>typedef enum { fast = 1 &lt;&lt; 0, slow = 1 &lt;&lt; 1, strong = 1 &lt;&lt; 2, smart = 1 &lt;&lt; 3, agile = 1 &lt;&lt; 4, } Skills; </code></pre> <hr /> <p><strong>EDIT:</strong></p> <p>OK, since this is an assignment, let me go through some trouble explaining how this works:</p> <p>As am sure you know, your enums look something like this (Binary):</p> <pre><code>(00001) (00010) ... (10000) </code></pre> <p>Now, using the bit-wise OR operator <code>|</code>, you were able to merge two skills together:</p> <pre><code> 00001 OR 01000 _____ 01001 </code></pre> <p>Then, we can check if that new multi-skill enum has some specific skill using <code>&amp;</code>:</p> <pre><code> 01001 AND 01000 _____ 01000 != 0 (aka true) </code></pre> <p>To go to a more advance level, we use XOR, which by definition, sets the resulting bit to <code>0</code> if the two bits are equal:</p> <pre><code> 01001 XOR 01000 _____ 00001 != 0 (aka true) 01001 XOR 01001 _____ 00000 == 0 (aka false) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload