Created
November 8, 2023 00:47
-
-
Save emoacht/7b595c23b6bb36dcc5923a32f3b8242a to your computer and use it in GitHub Desktop.
Convert 4 data bytes to unsigned integer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class BytesConverter | |
{ | |
/// <summary> | |
/// Converts 4 data bytes to unsigned integer. | |
/// </summary> | |
/// <param name="mh">High order bytes when using four data bytes</param> | |
/// <param name="ml">Low order bytes when using four data bytes</param> | |
/// <param name="sh">High order bytes when using two data bytes</param> | |
/// <param name="sl">Low order bytes when using two data bytes</param> | |
/// <returns>Unsigned integer</returns> | |
public static uint Convert(byte mh, byte ml, byte sh, byte sl) | |
{ | |
//return (mh << 24) + (ml << 16) + (sh << 8) + sl; | |
return BitConverter.ToUInt32(new[] { sl, sh, ml, mh }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment