title: Setting a bit in an uint64_t in c
body: <p>Hello I would like to set a bit ( value ) at a pos ( from left to right ). Here is my code that doesn't work for uint64_t ( here it should return 0 and not 1 ) but when I change values to make it works ( with the same logic ) with uint8_t it works. Any ideas? Please.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;inttypes.h&gt;
  int main()
  {
      uint64_t x = (uint64_t)1;
      int pos =  63;
      bool value = 0;
      uint8_t z = x;
      z = z &gt;&gt; (64-pos);
      z = z &lt;&lt; (64-pos);
      uint64_t a = (uint64_t)1;
      uint64_t d = (uint64_t)0;
      uint64_t y;
      uint64_t c = d;
      uint64_t b = x;
      b = b &lt;&lt; (pos+1);
      b = b &gt;&gt; (pos+1);
      if (value == 1)
      {
          y = a;
          y = y &lt;&lt; (63-pos);
      }
      else
      {
          y=d;
      }
      c = c|z|y|b;
      printf("%lld",c);
      return c;
  }
  </code></pre>
  
  <p>EDIT : I think there is a misunderstood ( I haven't be clear enough, my bad ), actually I have x that is an uint64_t and I have a int pos that is the position of one bit in x, and I have value that is a boolean ( 1 or 0 ) and if value is 1 the bit at the pos in x must become/stay 1 and if value is 0 the bit at the pos in x must become/stay 0.</p>