How to set/flip bitfields in C
<p>I am trying to have a <code>uint64_t</code> bitfield be all set to 0. Then when I call the function within the given string, and it matches with the static global array that I have set it will flip the bit to 1. Currently I have the following code but for some reason when giving it different strings it is following the same behavior. So for example when I input the following string of "ABC" it should be printing out <code>111000</code>. How would I get the following behavior.</p>

<pre><code>const size_t SETSIZE = sizeof(uint64_t) &lt;&lt; 3;
char key[5] = { 'A', 'B', 'C', 'D', 'E', 'F' }

uint64_t set_encode(char *st) {
    int i, j;
    uint64_t set = 0;
    int length = strlen(st);
    for (i = 0; i &lt; length; i++) {
        for (j = 0; j &lt; 5; j++) {
            if (st[i] == key[j]) {
                printf("%c", st[0]);
                set = set | 1 &lt;&lt; (SETSIZE - 1 - i);
            }
        }
    }
    printf("%lu\n", set);
    return set;
}
</code></pre>