It's probably best to handle it in C (the less people writing in JS have to be aware of the better). Perhaps you could do something like data & ((1<<databits)-1) and then it'd be vaguely compatible with any number of bits.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Great!
It's probably best to handle it in C (the less people writing in JS have to be aware of the better). Perhaps you could do something like
data & ((1<<databits)-1)
and then it'd be vaguely compatible with any number of bits.