title: 32-bits as hex number in C with simple function call
body: <p>I would like to know if I could get away with using printf to print 32 bits of incoming binary data from a microcontroller as a hexadecimal number. I already have collected the bits into an large integer variable and I'm trying "%x" option in printf but all I seem to get are 8-bit values, although I can't tell if that's a limitation with printf or my microcontroller is actually returning that value.</p>
  
  <p>Here's my code to receive data from the microcontroller:</p>
  
  <pre><code> printf("Receiving...\n");
   unsigned int n=0,b=0;
   unsigned long lnum=0;
   b=iolpt(1); //call to tell micro we want to read 32 bits
   for (n=0;n&lt;32;n++){
       b=iolpt(1); //read bit one at a time
       printf("Bit %d of 32 = %d\n",n,b);
       lnum&lt;&lt;1; //shift bits in our big number left by 1 position
       lnum+=b; //and add new value
   }
   printf("\n Data returned: %x\n",lnum); //always returns 8-bits
  </code></pre>
  
  <p>The iolpt() function always returns the bit read from the microcontroller and the value returned is a 0 or 1.</p>
  
  <p>Is my idea of using %x acceptable for a 32-bit hexadecimal number or should I attempt something like "%lx" instead of "%x" to try to represent long hex even though its documented nowhere or is printf the wrong function for 32-bit hex? If its the wrong function then is there a function I can use that works, or am I forced to break up my long number into four 8-bit numbers first?</p>