<p>Hey! I was looking at this code at <a href="http://www.gnu.org/software/m68hc11/examples/primes_8c-source.html" rel="noreferrer">http://www.gnu.org/software/m68hc11/examples/primes_8c-source.html</a></p>

<p>I noticed that in some situations they used hex numbers, like in line 134:</p>

<pre><code>for (j = 1; val &amp;&amp; j &lt;= 0x80; j &lt;&lt;= 1, q++)
</code></pre>

<p>Now why would they use the 0x80? I am not that good with hex but I found an online hex to decimal and it gave me 128 for 0x80.</p>

<p>Also before line 134, on line 114 they have this:</p>

<pre><code>small_n = (n &amp; 0xffff0000) == 0;
</code></pre>

<p>The hex to decimal gave me 4294901760 for that hex number.
So here in this line they are making a bit AND and comparing the result to 0??</p>

<p>Why not just use the number?
Can anyone please explain and please do give examples of other situations.</p>

<p>Also I have seen large lines of code where it's just hex numbers and never really understood why :(</p>

In both cases you cite, the bit pattern of the number is important, not the actual number.
For example,
In the first case,
```
j
```
is going to be 1, then 2, 4, 8, 16, 32, 64 and finally 128 as the loop progresses.
In binary, that is,
```
0000:0001
```
,
```
0000:0010
```
,
```
0000:0100
```
,
```
0000:1000
```
,
```
0001:0000
```
,
```
0010:0000
```
,
```
0100:0000
```
and
```
1000:0000
```
.
There's no option for binary constants in C (until C23) or C++ (until C++14), but it's a bit clearer in Hex:
```
0x01
```
,
```
0x02
```
,
```
0x04
```
,
```
0x08
```
,
```
0x10
```
,
```
0x20
```
,
```
0x40
```
, and
```
0x80
```
.
In the second example,
the goal was to remove the lower two bytes of the value.
So given a value of 1,234,567,890 we want to end up with 1,234,567,168.
In hex, it's clearer: start with
```
0x4996:02d2
```
, end with
```
0x4996:0000
```
.