Set a specific bit to a specific value
This is simpler:

#include &lt;stdint.h&gt; // #include &lt;cstdint&gt; in C++

void write_bit_32b(uint32_t *num, uint8_t pos, bool val)
{

        *num &amp;= ~(UINT32_C(1) &lt;&lt; pos);
        *num |= (uint32_t)val &lt;&lt; pos;
}




Use fixed-width integers if you can (see above).



Use int main(void):

C17::6.11.6: 


  Function declarators The use of function declarators with empty
  parentheses (not prototype-format parameter type declarators) is an
  obsolescent feature.




This may be interesting to you:

https://stackoverflow.com/q/47981/6872717