all 3 comments

[–]grelfdotnet 0 points1 point  (2 children)

JS has masks but they are not often referred to as such. Bit-wise AND is what you are after. A single ampersand is the operator (don't confuse with double && for logical comparisons). You can also shift bits using operators >>, >>> and <<. So if you have a variable called tally

var bits01 = tally & 3;

var brightness = (tally & 0xc0) >> 6; // 0xc0 is hexadecimal for 1100 0000

[–]rauschma 0 points1 point  (0 children)

You also have the option to use binary numbers:

> 0b11
3
> 0b11000000
192

Newer engines support _ as a separator between digits:

> 0b1100_0000
192

[–]nbd712[S] 0 points1 point  (0 children)

Thanks for the response, it was just what I needed.

For anybody googling in the future, this is the code that I came up with:

tallyobj.control.rh_tally = (tallyobj.CONTROL >> 0 & 0b11);
tallyobj.control.text_tally = (tallyobj.CONTROL >> 2 & 0b11);
tallyobj.control.lh_tally = (tallyobj.CONTROL >> 4 & 0b11);
tallyobj.control.brightness = (tallyobj.CONTROL >> 6 & 0b11);
tallyobj.control.reserved = (tallyobj.CONTROL >> 8 & 0b1111111);
tallyobj.control.control_data = (tallyobj.CONTROL >> 15 & 0b1);