Returns the specified single-precision floating point value as an array of bytes.
Namespace:
System
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public Shared Function GetBytes ( _
value As Single _
) As Byte()
Dim value As Single
Dim returnValue As Byte()
returnValue = BitConverter.GetBytes(value)
public static byte[] GetBytes(
float value
)
public:
static array<unsigned char>^ GetBytes(
float value
)
public static function GetBytes(
value : float
) : byte[]
Return Value
Type:
array<System..::.Byte>[]()[]An array of bytes with length 4.
The following code example converts the bit patterns of Single values to Byte arrays with the GetBytes method.
' Example of the BitConverter.GetBytes( Single ) method.
Imports System
Imports Microsoft.VisualBasic
Module GetBytesSingleDemo
Const formatter As String = "{0,16:E7}{1,20}"
' Convert a Single argument to a Byte array and display it.
Sub GetBytesSingle( argument As Single )
Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
Console.WriteLine( formatter, argument, _
BitConverter.ToString( byteArray ) )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the BitConverter.GetBytes( Single ) " & _
vbCrLf & "method generates the following " & _
"output." & vbCrLf )
Console.WriteLine( formatter, "Single", "Byte array" )
Console.WriteLine( formatter, "------", "----------" )
' Convert Single values and display the results.
GetBytesSingle( 0.0F )
GetBytesSingle( 1.0F )
GetBytesSingle( 15.0F )
GetBytesSingle( 65535.0F )
GetBytesSingle( 0.00390625F )
GetBytesSingle( 0.00000000023283064365386962890625F )
GetBytesSingle( 1.2345E-35F )
GetBytesSingle( 1.2345671F )
GetBytesSingle( 1.2345673F )
GetBytesSingle( 1.2345677F )
GetBytesSingle( 1.23456789E+35F )
GetBytesSingle( Single.MinValue )
GetBytesSingle( Single.MaxValue )
GetBytesSingle( Single.Epsilon )
GetBytesSingle( Single.NaN )
GetBytesSingle( Single.NegativeInfinity )
GetBytesSingle( Single.PositiveInfinity )
End Sub
End Module
' This example of the BitConverter.GetBytes( Single )
' method generates the following output.
'
' Single Byte array
' ------ ----------
' 0.0000000E+000 00-00-00-00
' 1.0000000E+000 00-00-80-3F
' 1.5000000E+001 00-00-70-41
' 6.5535000E+004 00-FF-7F-47
' 3.9062500E-003 00-00-80-3B
' 2.3283064E-010 00-00-80-2F
' 1.2345000E-035 49-46-83-05
' 1.2345671E+000 4B-06-9E-3F
' 1.2345673E+000 4D-06-9E-3F
' 1.2345676E+000 50-06-9E-3F
' 1.2345679E+035 1E-37-BE-79
' -3.4028235E+038 FF-FF-7F-FF
' 3.4028235E+038 FF-FF-7F-7F
' 1.4012985E-045 01-00-00-00
' NaN 00-00-C0-FF
' -Infinity 00-00-80-FF
' Infinity 00-00-80-7F
// Example of the BitConverter.GetBytes( float ) method.
using System;
class GetBytesSingleDemo
{
const string formatter = "{0,16:E7}{1,20}";
// Convert a float argument to a byte array and display it.
public static void GetBytesSingle( float argument )
{
byte[ ] byteArray = BitConverter.GetBytes( argument );
Console.WriteLine( formatter, argument,
BitConverter.ToString( byteArray ) );
}
public static void Main( )
{
Console.WriteLine(
"This example of the BitConverter.GetBytes( float ) " +
"\nmethod generates the following output.\n" );
Console.WriteLine( formatter, "float", "byte array" );
Console.WriteLine( formatter, "-----", "----------" );
// Convert float values and display the results.
GetBytesSingle( 0.0F );
GetBytesSingle( 1.0F );
GetBytesSingle( 15.0F );
GetBytesSingle( 65535.0F );
GetBytesSingle( 0.00390625F );
GetBytesSingle( 0.00000000023283064365386962890625F );
GetBytesSingle( 1.2345E-35F );
GetBytesSingle( 1.2345671F );
GetBytesSingle( 1.2345673F );
GetBytesSingle( 1.2345677F );
GetBytesSingle( 1.23456789E+35F );
GetBytesSingle( float.MinValue );
GetBytesSingle( float.MaxValue );
GetBytesSingle( float.Epsilon );
GetBytesSingle( float.NaN );
GetBytesSingle( float.NegativeInfinity );
GetBytesSingle( float.PositiveInfinity );
}
}
/*
This example of the BitConverter.GetBytes( float )
method generates the following output.
float byte array
----- ----------
0.0000000E+000 00-00-00-00
1.0000000E+000 00-00-80-3F
1.5000000E+001 00-00-70-41
6.5535000E+004 00-FF-7F-47
3.9062500E-003 00-00-80-3B
2.3283064E-010 00-00-80-2F
1.2345000E-035 49-46-83-05
1.2345671E+000 4B-06-9E-3F
1.2345673E+000 4D-06-9E-3F
1.2345676E+000 50-06-9E-3F
1.2345679E+035 1E-37-BE-79
-3.4028235E+038 FF-FF-7F-FF
3.4028235E+038 FF-FF-7F-7F
1.4012985E-045 01-00-00-00
NaN 00-00-C0-FF
-Infinity 00-00-80-FF
Infinity 00-00-80-7F
*/
// Example of the BitConverter::GetBytes( float ) method.
using namespace System;
// Convert a float argument to a byte array and display it.
void GetBytesSingle( float argument )
{
array<Byte>^byteArray = BitConverter::GetBytes( argument );
Console::WriteLine( "{0,16:E7}{1,20}", argument, BitConverter::ToString( byteArray ) );
}
int main()
{
Console::WriteLine( "This example of the BitConverter::GetBytes( float ) "
"\nmethod generates the following output.\n" );
Console::WriteLine( "{0,16:E7}{1,20}", "float", "byte array" );
Console::WriteLine( "{0,16:E7}{1,20}", "-----", "----------" );
// Convert float values and display the results.
GetBytesSingle( 0.0F );
GetBytesSingle( 1.0F );
GetBytesSingle( 15.0F );
GetBytesSingle( 65535.0F );
GetBytesSingle( 0.00390625F );
GetBytesSingle( 0.00000000023283064365386962890625F );
GetBytesSingle( 1.2345E-35F );
GetBytesSingle( 1.2345671F );
GetBytesSingle( 1.2345673F );
GetBytesSingle( 1.2345677F );
GetBytesSingle( 1.23456789E+35F );
GetBytesSingle( Single::MinValue );
GetBytesSingle( Single::MaxValue );
GetBytesSingle( Single::Epsilon );
GetBytesSingle( Single::NaN );
GetBytesSingle( Single::NegativeInfinity );
GetBytesSingle( Single::PositiveInfinity );
}
/*
This example of the BitConverter::GetBytes( float )
method generates the following output.
float byte array
----- ----------
0.0000000E+000 00-00-00-00
1.0000000E+000 00-00-80-3F
1.5000000E+001 00-00-70-41
6.5535000E+004 00-FF-7F-47
3.9062500E-003 00-00-80-3B
2.3283064E-010 00-00-80-2F
1.2345000E-035 49-46-83-05
1.2345671E+000 4B-06-9E-3F
1.2345673E+000 4D-06-9E-3F
1.2345676E+000 50-06-9E-3F
1.2345679E+035 1E-37-BE-79
-3.4028235E+038 FF-FF-7F-FF
3.4028235E+038 FF-FF-7F-7F
1.4012985E-045 01-00-00-00
NaN 00-00-C0-FF
-Infinity 00-00-80-FF
Infinity 00-00-80-7F
*/
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference