how to convert two bytes to decimal value. i have two bytes 0x00F4 and 0x0001 . and decimal value is 500. how to convert ? in c# code.
How to convert two bytes to decimal value
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Amit MohantyRank #112 · 20K reputationPosted Feb 22, 2024, 5:55 AM EST
Check this:
public class Program { public static void Main() { byte byte1 = 0x00F4; byte byte2 = 0x0001; ushort combinedValue = (ushort)((byte2 << 8) | byte1); decimal decimalValue = Convert.ToUInt16(combinedValue); Console.WriteLine("Decimal value: " + decimalValue); } }Jithu ThomasRank #437 · 5.7K reputationPosted Feb 22, 2024, 8:04 AM EST
using System; class Program { static void Main() { byte[] byteArray = { 0x00F4, 0x0001 }; ushort value = BitConverter.ToUInt16(byteArray, 0); Console.WriteLine($"Decimal value: {value}"); Console.ReadLine(); } }Output: -