C# BitConverter ToSingle
Description
BitConverter ToSingle
returns a single-precision floating
point number converted from four bytes at a specified position in a byte array.
Syntax
BitConverter.ToSingle
has the following syntax.
public static float ToSingle(
byte[] value,
int startIndex
)
Parameters
BitConverter.ToSingle
has the following parameters.
value
- An array of bytes.startIndex
- The starting position within value.
Returns
BitConverter.ToSingle
method returns A single-precision floating point number formed by four bytes beginning
at startIndex.
Example
The following code example converts elements of Byte arrays to Single values with the ToSingle method.
using System;/* w ww .j a va 2 s.c om*/
class BytesToSingleDemo
{
public static void Main( )
{
byte[ ] bytes = {
77, 6, 158, 63, 80, 6, 158, 63, 30, 55,
190, 121, 255, 255, 127, 255, 255, 127, 127, 1,
0, 128, 127 };
float value = BitConverter.ToSingle( bytes, 0 );
Console.WriteLine(value );
}
}
The code above generates the following result.