Bitwise operations - a frame and a template

Hello.
I try to create a decoder.
I have some frames for decoding. When the frame matches to template then the function (fn decode_frame(..)) has to return true. If not false.

    // LEGEND:
    // X - CONST VALUE
    // I - DYNAMIC (0 or 1) 
    
    // FRAME 1 dec: 379584768
    // VALUE: 000 1011 0101 0000 0000 00001 0000 0000 
    // TEMPL: XXX XXX  XXXX IIII IIII XXXXX IIII IIII 
    
    // FRAME 1.1 dec: 379584943
    // VALUE: 000 1011 0101 0000 0000 00001 1010 1111
    // TEMPL: XXX XXX  XXXX IIII IIII XXXXX IIII IIII 
    
    // FRAME 2 dec: 400556288
    // VALUE: 000 1011 1111 0000 0000 00001 0000 0000
    // TEMPL: XXX XXX  XXXX IIII IIII XXXXX IIII IIII 
    
    // FRAME 2.1 dec: 400564681
    // VALUE: 000 1011 1111 0000 0001 00001 1100 1001
    // TEMPL: XXX XXX  XXXX IIII IIII XXXXX IIII IIII

How to do it? Bit-mask (AND) is not enough.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eb148864d13a71dbafc0d71c9b314cc7

Make dynamic I bits all 0s in the template, XOR the template with the frame value, mask out the dynamic bits using bitwise &, and if the result is all 0s, then the value matches the template. Playground.

1 Like

Thanks for your help.

My Playground