rogier
19 January 2022 22:07
1
i want to convert 16 time single bit into one 16 bit value for my modbus project. when 1 bit input change the 16 bit value has also to change. There has to be a memory of all the states of the inputs... has somebody an solution?
This should get you started...
If you mean combining bits to make a WORD value - its just basic math functionality of the programming language.
e.g....
//Get bit
function getBit(number, bitPosition) {
return (number & (1 << bitPosition)) === 0 ? 0 : 1;
}
//Set Bit
function setBit(number, bitPosition) {
return number | (1 << bitPosition);
}
//Clear Bit
function clearBit(number, bitPosition) {
const mask = ~(1 << bitPosition);
return number & mask;
}
//Update Bit
function updateBit(number, bitPosition, bitValue) {
…
system
Closed
20 March 2022 22:45
3
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.