title: How to implement bitmap array in C using uint64_t data type?
body: <p>I am trying to implement bitmap array in C.
  I've read and copy-paste from this link: <a href="https://stackoverflow.com/questions/1225998/what-is-a-bitmap-in-c">What is a bitmap in C?</a>  </p>
  
  <pre><code>#include &lt;limits.h&gt;    /* for CHAR_BIT */
  #include &lt;stdint.h&gt;   /* for uint32_t */
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef uint32_t word_t; // I want to change this, from uint32_t to uint64_t
  enum { BITS_PER_WORD = sizeof(word_t) * CHAR_BIT };
  #define WORD_OFFSET(b) ((b) / BITS_PER_WORD)
  #define BIT_OFFSET(b)  ((b) % BITS_PER_WORD)
  
  void set_bit(word_t *words, int n) { 
    words[WORD_OFFSET(n)] |= (1 &lt;&lt; BIT_OFFSET(n));
  }
  
  void clear_bit(word_t *words, int n) {
    words[WORD_OFFSET(n)] &amp;= ~(1 &lt;&lt; BIT_OFFSET(n)); 
  }
  
  int get_bit(word_t *words, int n) {
    word_t bit = words[WORD_OFFSET(n)] &amp; (1 &lt;&lt; BIT_OFFSET(n));
    return bit != 0; 
  }
  
  int main(){
    printf("sizeof(word_t)=%i\n",sizeof(word_t));
    printf("CHAR_BIT=%i\n",CHAR_BIT);
    printf("BITS_PER_WORD=%i\n",BITS_PER_WORD);
    word_t x;
  
    set_bit(&amp;x, 0);
    printf("x=%u\n",x);
    set_bit(&amp;x, 1);
    printf("x=%u\n",x);
    set_bit(&amp;x, 2);
    printf("x=%u\n",x);
  
    return 0;
  }
  </code></pre>
  
  <p>Using uint32_t, the code works well. It prints x value: 1, 3, and 7, respectively like this:</p>
  
  <pre><code>[izzatul@mycomputer latihan]$ ./a.out
  sizeof(word_t)=8
  CHAR_BIT=8
  BITS_PER_WORD=64
  x=1
  x=3
  </code></pre>
  
  <p>x=7</p>
  
  <p>It doesn't work. The x value become 1295807169 etc, which was not I expected. I expect it to be the same as before (1, 3, 7). Can someone help me fix that code?</p>
  
  <p>I know "&lt;&lt;" is bit shifting, which mean you shift the bit to the left (or adding 0 to the right).
  But I am still not sure how to modify the code myself.</p>