From fadd7d0cb396e16ce9283214cf3282fdee61881e Mon Sep 17 00:00:00 2001 From: Himmelt Date: Thu, 17 Aug 2023 13:33:07 +0800 Subject: [PATCH] update params descriptions and change param name from "bitPosition" to "index" --- S7.Net/Conversion.cs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/S7.Net/Conversion.cs b/S7.Net/Conversion.cs index ce1f463..8a53fb8 100644 --- a/S7.Net/Conversion.cs +++ b/S7.Net/Conversion.cs @@ -138,14 +138,14 @@ namespace S7.Net /// /// Helper to get a bit value given a byte and the bit index. - /// Example: DB1.DBX0.5 -> var bytes = ReadBytes(DB1.DBW0); bool bit = bytes[0].SelectBit(5); + /// Example: DB1.DBX0.5 -> var bytes = ReadBytes(DB1.DBW0); bool bit = bytes[0].SelectBit(5); /// - /// - /// - /// - public static bool SelectBit(this byte data, int bitPosition) + /// byte data get from + /// bit index + /// bool value will get + public static bool SelectBit(this byte data, int index) { - int mask = 1 << bitPosition; + int mask = 1 << index; int result = data & mask; return (result != 0); @@ -153,25 +153,26 @@ namespace S7.Net /// /// Helper to set a bit value to the given byte at the bit index. + /// Example: byte data = (byte)0x00; data.SetBit(4, true);// data -> 0x10 /// - /// - /// - /// - public static void SetBit(this ref byte data, int bitPosition, bool value) + /// byte data to be modified + /// bit index + /// bool value to set + public static void SetBit(this ref byte data, int index, bool value) { - if ((uint)bitPosition > 7) + if ((uint)index > 7) { return; } if (value) { - byte mask = (byte)(1 << bitPosition); + byte mask = (byte)(1 << index); data |= mask; } else { - byte mask = (byte)~(1 << bitPosition); + byte mask = (byte)~(1 << index); data &= mask; } }