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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version