title: Bit vector operations and Endianess
body: <p>I do a lot of bit vector operations in my software. For example: suppose I need to store boolean information about a candidate 'n', I do the following:</p>
  
  <pre><code>uint64_t *information_vector;
  uint32_t pos = n / 64;
  uint32_t bit_pos = n % 64;
  
  information_vector[pos] |= (1 &lt;&lt; bit_pos);
  </code></pre>
  
  <p>and I follow similar procedure while reading that information:</p>
  
  <pre><code>uint32_t pos = n / 64;
  uint32_t bit_pos = n % 64;
  if (information_vector[pos] &amp; (1 &lt;&lt; bit_pos)) {
         // do something
  }
  </code></pre>
  
  <p>In the meantime, I also write the information_vector to the disk and read it back again. Now, I am trying to solve a bug which is giving me nightmares and it struck me that Endianess might be a culprit here but I can not explain. Is there any way I can check? Is this bit vector manipulation generally endian safe and across architectures?</p>
  
  <p>I also see that somewhere in the code I set some other information in another bit vector for the same candidate as:</p>
  
  <pre><code>uint8_t byte_position = n / 8;
  uint8_t bit_position = n % 8;
  another_information_vector[byte_position] |= (1 &lt;&lt; bit_position);
  </code></pre>
  
  <p>I usually find common set of attributes by and-ing these bit vectors.</p>