private void Write4Bits(int value) { ushort gpio = mcp23017.ReadGpioAB(); for (int i = 0; i < 4; i++) { gpio &= (ushort)(~(1 << dataPins[i])); gpio |= (ushort)(((value >> i) & 0x01) << dataPins[i]); } mcp23017.WriteGpioAB(gpio); gpio |= (ushort)(1 << enablePin); mcp23017.WriteGpioAB(gpio); gpio &= (ushort)((~(1 << enablePin)) & 0xFFFF); // who promotes to int on bit negation?!? mcp23017.WriteGpioAB(gpio); }