Matching binary patterns in C <p>I'm currently developing a C program that needs to parse some bespoke data structures, fortunately I know how they are structured, however I'm not sure of how to implement my parser in C.</p> <p>Each of the structures are 32-bits in length, and each structure can be identified by it's binary signature.</p> <p>As an example, there are two particular structures that I'm interested in, and they have the following binary patterns (x means either 0 or 1)</p> <pre><code> 0000-00xx-xxxx-xxx0 0000-10xx-10xx-xxx0 </code></pre> <p>Within these structures the 'x' bits contain the actual data I need, so essentially I need a way of identifying each structure based on how the bits are written within each structure.</p> <p>So as an example in pseudo-code:</p> <pre><code>if (binaryPattern = 000010xxxxxxxxx0) { do something with it; } </code></pre> <p>I'm guessing that reading them as ints, and then performing some kind of bitmasking would be the way to go, but my knowledge of C isn't great, and maybe a simple logical OR operation would do it, but I just wanted some advice on doing this before I start.</p> <p>Thanks</p> <p>Thanks very much to everyone that has answered, very helpful!!</p>