How do I compare two binary values in Javascript?

Consider that I have an 8 bit number, let’s say 00101101, and I want to check whether the third bit from the right is one or zero.

I imagine could do ( 00101101 AND 00000100 ), and if the result is anything other than zero I would know that bit 3’s value is one.
Is there a way to do this in Unity? Is there a different way than the one I’m proposing?

I imagine this must be very simple, but I can’t find any reference in the docs.
Thanks!

P.S. The reason I’m doing this is for a tiling system. I need to adjust some mesh colliders based on their surroundings. Without this kind of binary comparison the code is becoming too unwieldy, very long and with tons of special cases. I believe I can simplify things a bit if this is possible.

Your approach is exactly right, and you just need to use the binary logical AND operator, which is a single ampersand “&”, not to be confused with the conditional AND, which is far more common and a double ampersand “&&”. There is information about this operator, and more, on MSDN:

A small code sample:

    byte number = 0x2D; // 00101101
    byte mask = 4; // 00000100

    bool thirdBitOne = (number & mask) > 0;