Skip to content

Commit

Permalink
Update S7.Net/Conversion.cs
Browse files Browse the repository at this point in the history
Co-authored-by: Günther Foidl <[email protected]>
  • Loading branch information
Himmelt and gfoidl authored Aug 16, 2023
1 parent 9c0fea7 commit 652ff3a
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions S7.Net/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,33 +166,13 @@ public static void SetBit(this ref byte data, int bitPosition, bool value)

if (value)
{
switch (bitPosition)
{
case 0: data |= 0x01; return;
case 1: data |= 0x02; return;
case 2: data |= 0x04; return;
case 3: data |= 0x08; return;
case 4: data |= 0x10; return;
case 5: data |= 0x20; return;
case 6: data |= 0x40; return;
case 7: data |= 0x80; return;
default: return;
}
byte mask = (byte)(1 << bitPosition);
data |= mask;
}
else
{
switch (bitPosition)
{
case 0: data &= 0xFE; return;
case 1: data &= 0xFD; return;
case 2: data &= 0xFB; return;
case 3: data &= 0xF7; return;
case 4: data &= 0xEF; return;
case 5: data &= 0xDF; return;
case 6: data &= 0xBF; return;
case 7: data &= 0x7F; return;
default: return;
}
byte mask = (byte)~(1 << bitPosition);
data &= mask;
}
}

Expand Down

0 comments on commit 652ff3a

Please sign in to comment.