i am new to c# i have been working on controlling a io card
i have no issue writing to turn on / toggle / or get status
turn on bits |= 1 << bit;
toggle bits ^= 1 << bit;
but i cannot get the item pin to turn off i do not want to use toggle because i want it
to either be on or off
now when i turn off the pin basicly unset the pins i always get a error about it setting a negative number to a ushort
any help would be greatly appreciated
bits &= ~(1 << bit);
`
//=============================================================
//program.cs these are my calls from the main program
//============================================================
if (whatTheUserTyped == "on")
{
Console.WriteLine(Control.PinOn(2,3,4,5,6));
}
if (whatTheUserTyped == "off")
{
Console.WriteLine(Control.PinOff(4));
}
//==========================================================
// control.cs
//==========================================================
public string PinOn(int pin1)
{
bits |= Convert.ToUInt16(1 << pin1);
return "pin on";
}
public string PinOff(int pin1)
{
bits &= ~(1 << 3);
WriteToCard();
return "pin off";
}
`