 <p>If you do not mind additional statements (while loop) the following will work in c99</p> <pre><code>#define NBITS_32(n,out_len) 0; while (n &amp;&amp; !(0x80000000 &gt;&gt; out_len &amp; n)) out_len++; out_len = n ? abs(out_len - 32) : n uint8_t len1 = NBITS_32(0x0F000000, len1); uint8_t len2 = NBITS_32(0x00008000, len2); uint8_t len3 = NBITS_32(0xFFFFFFFF, len3); uint8_t len4 = NBITS_32(0x00000001, len4); printf("%u\n%u\n%u\n%u\n", len1, len2, len3, len4); </code></pre> <p>Output:</p> <blockquote> <p><strong>28<br/> 16<br/> 32<br/> 1</strong></p> </blockquote>