Search code examples
c#arrayschardata-conversion

C# : how to convert char array into float


I have a byte array of four bytes which contains the byts of a FLOAT values. For example

array[0]=0x1F

array[1]=0x05

array[2]=0x01

array[3]=0x42

this should be 0x4201051f, which means 32.255 value.

Do you have any suggestion on how to group the array and save the value in a float data?

Thank you


Solution

  • As suggested by shingo, the linked question provides the answer:

    var input = new byte[] { 0x1F, 0x05, 0x01, 0x42 };
    Console.WriteLine(BitConverter.ToSingle(input, 0)); // Outputs 32.255