title: C bit-wise operations with hex numbers
body: <p>Is there a way to access certain parts of a hexadecimal number in C?</p>
  
  <p>I want to write a function that takes in a hexadecimal number and negates it, but leaves the least significant byte unchanged. Example: 0x87654321 should become 0x789ABC21.</p>
  
  <p>I've tried to somehow save the LSB and then apply it to the negated x, but my problem is that my mask gets applied to all bytes. I could hard code it for a specific value, but obviously that's not what I want.</p>
  
  <pre><code>void b(int x) {
    int temp = x &amp; 0xFF; // temp is all 0 with the LSB being the same as x's
    x = ~x;  // this negates x
    // one of a couple of attempts I tried thus far:
    // x = (x &amp; 0x00) | temp; 
    // idea: change x's LSB to 00 and OR it with temp, 
    // changing x's LSB to temp's LSB
  }
  </code></pre>
  
  <p>I'd appreciate if you don't post code for the solution, but rather just answer whether there is a way to apply bit operations to specific sections of a hexadecimal number, or how I could possibly solve this.</p>