take 4 bits out of an int and convert to byte

You are providing a number that is overflowing. You could use the code bellow, but it will take only the four least significant bits. If the number is greater than 0x0F, the other bits will be ignored.

commandData[7] = Convert.ToByte((SomeNumricData & 0x0F) | ((OtherNumericData << 4) & 0xF0));

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top