Skip to content

Instantly share code, notes, and snippets.

@emoacht
Created November 8, 2023 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emoacht/7b595c23b6bb36dcc5923a32f3b8242a to your computer and use it in GitHub Desktop.
Save emoacht/7b595c23b6bb36dcc5923a32f3b8242a to your computer and use it in GitHub Desktop.
Convert 4 data bytes to unsigned integer.
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