BitConverter.GetBytes Yöntem

Tanım

Belirtilen verileri bayt dizisine dönüştürür.

Aşırı Yüklemeler

GetBytes(Boolean)

Belirtilen Boole değerini bayt dizisi olarak döndürür.

GetBytes(Char)

Belirtilen Unicode karakter değerini bayt dizisi olarak döndürür.

GetBytes(Double)

Belirtilen çift duyarlıklı kayan nokta değerini bayt dizisi olarak döndürür.

GetBytes(Half)

Belirtilen yarım duyarlıklı kayan nokta değerini bayt dizisi olarak döndürür.

GetBytes(Int128)

Belirtilen 128 bit imzalı tamsayı değerini bayt dizisi olarak döndürür.

GetBytes(Int16)

Belirtilen 16 bit imzalı tamsayı değerini bayt dizisi olarak döndürür.

GetBytes(Int32)

Belirtilen 32 bit imzalı tamsayı değerini bayt dizisi olarak döndürür.

GetBytes(Int64)

Belirtilen 64 bit imzalı tamsayı değerini bayt dizisi olarak döndürür.

GetBytes(Single)

Belirtilen tek duyarlıklı kayan nokta değerini bayt dizisi olarak döndürür.

GetBytes(UInt128)

Belirtilen 128 bit işaretsiz tamsayı değerini bayt dizisi olarak döndürür.

GetBytes(UInt16)

Belirtilen 16 bit işaretsiz tamsayı değerini bayt dizisi olarak döndürür.

GetBytes(UInt32)

Belirtilen 32 bit işaretsiz tamsayı değerini bayt dizisi olarak döndürür.

GetBytes(UInt64)

Belirtilen 64 bit işaretsiz tamsayı değerini bayt dizisi olarak döndürür.

GetBytes(Boolean)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Belirtilen Boole değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(bool value);

Parametreler

value
Boolean

Dönüştürülecek değer.

Döndürülenler

Byte[]

Uzunluğu 1 olan bir bayt dizisi.

Örnekler

Aşağıdaki örnek, Boolean değerlerin bit desenlerini GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
using System;

class Example
{
   public static void Main( )
   {
      // Define Boolean true and false values.
      bool[] values = { true, false };

      // Display the value and its corresponding byte array.
      Console.WriteLine("{0,10}{1,16}\n", "Boolean", "Bytes");
      foreach (var value in values) {
         byte[] bytes = BitConverter.GetBytes(value);
         Console.WriteLine("{0,10}{1,16}", value,
                           BitConverter.ToString(bytes));
      }
   }
}
// The example displays the following output:
//        Boolean           Bytes
//
//           True              01
//          False              00

Açıklamalar

ToBoolean yöntemini çağırarak bayt dizisini Boolean bir değere geri dönüştürebilirsiniz.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(Char)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Belirtilen Unicode karakter değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(char value);

Parametreler

value
Char

Dönüştürülecek karakter.

Döndürülenler

Byte[]

Uzunluğu 2 olan bayt dizisi.

Örnekler

Aşağıdaki kod örneği, Char değerlerin bit desenlerini (Unicode karakterleri) GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
// Example of the BitConverter.GetBytes( char ) method.
using System;

class GetBytesCharDemo
{
    const string formatter = "{0,10}{1,16}";

    // Convert a char argument to a byte array and display it.
    public static void GetBytesChar( char 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( char ) " +
            "\nmethod generates the following output.\r\n" );
        Console.WriteLine( formatter, "char", "byte array" );
        Console.WriteLine( formatter, "----", "----------" );

        // Convert char values and display the results.
        GetBytesChar( '\0' );
        GetBytesChar( ' ' );
        GetBytesChar( '*' );
        GetBytesChar( '3' );
        GetBytesChar( 'A' );
        GetBytesChar( '[' );
        GetBytesChar( 'a' );
        GetBytesChar( '{' );
    }
}

/*
This example of the BitConverter.GetBytes( char )
method generates the following output.

      char      byte array
      ----      ----------
                     00-00
                     20-00
         *           2A-00
         3           33-00
         A           41-00
         [           5B-00
         a           61-00
         {           7B-00
*/

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(Double)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Belirtilen çift duyarlıklı kayan nokta değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(double value);

Parametreler

value
Double

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 8 olan bayt dizisi.

Örnekler

Aşağıdaki kod örneği, Double değerlerin bit desenlerini GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
// Example of the BitConverter.GetBytes( double ) method.
using System;

class GetBytesDoubleDemo
{
    const string formatter = "{0,25:E16}{1,30}";

    // Convert a double argument to a byte array and display it.
    public static void GetBytesDouble( double 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( double ) " +
            "\nmethod generates the following output.\n" );
        Console.WriteLine( formatter, "double", "byte array" );
        Console.WriteLine( formatter, "------", "----------" );

        // Convert double values and display the results.
        GetBytesDouble( 0.0 );
        GetBytesDouble( 1.0 );
        GetBytesDouble( 255.0 );
        GetBytesDouble( 4294967295.0 );
        GetBytesDouble( 0.00390625 );
        GetBytesDouble( 0.00000000023283064365386962890625 );
        GetBytesDouble( 1.23456789012345E-300 );
        GetBytesDouble( 1.2345678901234565 );
        GetBytesDouble( 1.2345678901234567 );
        GetBytesDouble( 1.2345678901234569 );
        GetBytesDouble( 1.23456789012345678E+300 );
        GetBytesDouble( double.MinValue );
        GetBytesDouble( double.MaxValue );
        GetBytesDouble( double.Epsilon );
        GetBytesDouble( double.NaN );
        GetBytesDouble( double.NegativeInfinity );
        GetBytesDouble( double.PositiveInfinity );
    }
}

/*
This example of the BitConverter.GetBytes( double )
method generates the following output.

                   double                    byte array
                   ------                    ----------
  0.0000000000000000E+000       00-00-00-00-00-00-00-00
  1.0000000000000000E+000       00-00-00-00-00-00-F0-3F
  2.5500000000000000E+002       00-00-00-00-00-E0-6F-40
  4.2949672950000000E+009       00-00-E0-FF-FF-FF-EF-41
  3.9062500000000000E-003       00-00-00-00-00-00-70-3F
  2.3283064365386963E-010       00-00-00-00-00-00-F0-3D
  1.2345678901234500E-300       DF-88-1E-1C-FE-74-AA-01
  1.2345678901234565E+000       FA-59-8C-42-CA-C0-F3-3F
  1.2345678901234567E+000       FB-59-8C-42-CA-C0-F3-3F
  1.2345678901234569E+000       FC-59-8C-42-CA-C0-F3-3F
  1.2345678901234569E+300       52-D3-BB-BC-E8-7E-3D-7E
 -1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-FF
  1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-7F
  4.9406564584124654E-324       01-00-00-00-00-00-00-00
                      NaN       00-00-00-00-00-00-F8-FF
                -Infinity       00-00-00-00-00-00-F0-FF
                 Infinity       00-00-00-00-00-00-F0-7F
*/

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(Half)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Belirtilen yarım duyarlıklı kayan nokta değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(Half value);

Parametreler

value
Half

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 2 olan bayt dizisi.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET 6, 7, 8, 9, 10

GetBytes(Int128)

Kaynak:
BitConverter.cs

Belirtilen 128 bit imzalı tamsayı değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(Int128 value);

Parametreler

value
Int128

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 16 olan bayt dizisi.

Şunlara uygulanır

.NET 10 ve .NET 9
Ürün Sürümler
.NET 9, 10

GetBytes(Int16)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Belirtilen 16 bit imzalı tamsayı değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(short value);

Parametreler

value
Int16

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 2 olan bayt dizisi.

Örnekler

Aşağıdaki kod örneği, Int16 değerlerin bit desenlerini GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
// Example of the BitConverter.GetBytes( short ) method.
using System;

class GetBytesInt16Demo
{
    const string formatter = "{0,10}{1,13}";

    // Convert a short argument to a byte array and display it.
    public static void GetBytesInt16( short 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( short ) " +
            "\nmethod generates the following output.\n" );
        Console.WriteLine( formatter, "short", "byte array" );
        Console.WriteLine( formatter, "-----", "----------" );

        // Convert short values and display the results.
        GetBytesInt16( 0 );
        GetBytesInt16( 15 );
        GetBytesInt16( -15 );
        GetBytesInt16( 10000 );
        GetBytesInt16( -10000 );
        GetBytesInt16( short.MinValue );
        GetBytesInt16( short.MaxValue );
    }
}

/*
This example of the BitConverter.GetBytes( short )
method generates the following output.

     short   byte array
     -----   ----------
         0        00-00
        15        0F-00
       -15        F1-FF
     10000        10-27
    -10000        F0-D8
    -32768        00-80
     32767        FF-7F
*/

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(Int32)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Belirtilen 32 bit imzalı tamsayı değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(int value);

Parametreler

value
Int32

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 4 olan bayt dizisi.

Örnekler

Aşağıdaki kod örneği, Int32 değerlerin bit desenlerini GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
using System;

class Example
{
    public static void Main( )
    {
        // Define an array of integers.
        int[] values = { 0, 15, -15, 0x100000,  -0x100000, 1000000000,
                         -1000000000, int.MinValue, int.MaxValue };

        // Convert each integer to a byte array.
        Console.WriteLine("{0,16}{1,10}{2,17}", "Integer",
                          "Endian", "Byte Array");
        Console.WriteLine("{0,16}{1,10}{2,17}", "---", "------",
                          "----------" );
        foreach (var value in values) {
          byte[] byteArray = BitConverter.GetBytes(value);
          Console.WriteLine("{0,16}{1,10}{2,17}", value,
                            BitConverter.IsLittleEndian ? "Little" : " Big",
                            BitConverter.ToString(byteArray));
        }
    }
}
// This example displays output like the following:
//              Integer    Endian       Byte Array
//                  ---    ------       ----------
//                    0    Little      00-00-00-00
//                   15    Little      0F-00-00-00
//                  -15    Little      F1-FF-FF-FF
//              1048576    Little      00-00-10-00
//             -1048576    Little      00-00-F0-FF
//           1000000000    Little      00-CA-9A-3B
//          -1000000000    Little      00-36-65-C4
//          -2147483648    Little      00-00-00-80
//           2147483647    Little      FF-FF-FF-7F

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(Int64)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Belirtilen 64 bit imzalı tamsayı değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(long value);

Parametreler

value
Int64

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 8 olan bayt dizisi.

Örnekler

Aşağıdaki örnek, bir Int64 dizisindeki her öğeyi Byte dizilere dönüştürmek için GetBytes yöntemini çağırır.

C#
using System;

class Example
{
    public static void Main()
    {
        // Define an array of Int64 values.
        long[] values = { 0, 0xFFFFFF, -0xFFFFFF, 1000000000, -1000000000,
                          0x100000000, -0x100000000, 0xAAAAAAAAAAAA,
                          -0xAAAAAAAAAAAA, 1000000000000000000,
                          -1000000000000000000, long.MinValue,
                          long.MaxValue };

        Console.WriteLine( "{0,22}{1,10} {2,30}", "Int64", "Endian", "Byte Array");
        Console.WriteLine( "{0,22}{1,10} {2,30}", "----", "------", "----------" );

        foreach (var value in values) {
            // Convert each Int64 value to a byte array.
            byte[] byteArray = BitConverter.GetBytes(value);
            // Display the result.
            Console.WriteLine("{0,22}{1,10}{2,30}", value,
                              BitConverter.IsLittleEndian ? "Little" : "Big",
                              BitConverter.ToString(byteArray));
        }
    }
}
// The example displays output like the following:
//                    Int64    Endian                     Byte Array
//                     ----    ------                     ----------
//                        0    Little       00-00-00-00-00-00-00-00
//                 16777215    Little       FF-FF-FF-00-00-00-00-00
//                -16777215    Little       01-00-00-FF-FF-FF-FF-FF
//               1000000000    Little       00-CA-9A-3B-00-00-00-00
//              -1000000000    Little       00-36-65-C4-FF-FF-FF-FF
//               4294967296    Little       00-00-00-00-01-00-00-00
//              -4294967296    Little       00-00-00-00-FF-FF-FF-FF
//          187649984473770    Little       AA-AA-AA-AA-AA-AA-00-00
//         -187649984473770    Little       56-55-55-55-55-55-FF-FF
//      1000000000000000000    Little       00-00-64-A7-B3-B6-E0-0D
//     -1000000000000000000    Little       00-00-9C-58-4C-49-1F-F2
//     -9223372036854775808    Little       00-00-00-00-00-00-00-80
//      9223372036854775807    Little       FF-FF-FF-FF-FF-FF-FF-7F

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(Single)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Belirtilen tek duyarlıklı kayan nokta değerini bayt dizisi olarak döndürür.

C#
public static byte[] GetBytes(float value);

Parametreler

value
Single

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 4 olan bayt dizisi.

Örnekler

Aşağıdaki kod örneği, Single değerlerin bit desenlerini GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
// 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
*/

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(UInt128)

Kaynak:
BitConverter.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen 128 bit işaretsiz tamsayı değerini bayt dizisi olarak döndürür.

C#
[System.CLSCompliant(false)]
public static byte[] GetBytes(UInt128 value);

Parametreler

value
UInt128

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 16 olan bayt dizisi.

Öznitelikler

Şunlara uygulanır

.NET 10 ve .NET 9
Ürün Sürümler
.NET 9, 10

GetBytes(UInt16)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen 16 bit işaretsiz tamsayı değerini bayt dizisi olarak döndürür.

C#
[System.CLSCompliant(false)]
public static byte[] GetBytes(ushort value);

Parametreler

value
UInt16

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 2 olan bayt dizisi.

Öznitelikler

Örnekler

Aşağıdaki kod örneği, UInt16 değerlerin bit desenlerini GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
// Example of the BitConverter.GetBytes( ushort ) method.
using System;

class GetBytesUInt16Demo
{
    const string formatter = "{0,10}{1,13}";

    // Convert a ushort argument to a byte array and display it.
    public static void GetBytesUInt16( ushort 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( ushort ) " +
            "\nmethod generates the following output.\n" );
        Console.WriteLine( formatter, "ushort", "byte array" );
        Console.WriteLine( formatter, "------", "----------" );

        // Convert ushort values and display the results.
        GetBytesUInt16( 15 );
        GetBytesUInt16( 1023 );
        GetBytesUInt16( 10000 );
        GetBytesUInt16( ushort.MinValue );
        GetBytesUInt16( (ushort)short.MaxValue );
        GetBytesUInt16( ushort.MaxValue );
    }
}

/*
This example of the BitConverter.GetBytes( ushort )
method generates the following output.

    ushort   byte array
    ------   ----------
        15        0F-00
      1023        FF-03
     10000        10-27
         0        00-00
     32767        FF-7F
     65535        FF-FF
*/

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(UInt32)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen 32 bit işaretsiz tamsayı değerini bayt dizisi olarak döndürür.

C#
[System.CLSCompliant(false)]
public static byte[] GetBytes(uint value);

Parametreler

value
UInt32

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 4 olan bayt dizisi.

Öznitelikler

Örnekler

Aşağıdaki kod örneği, UInt32 değerlerin bit desenlerini GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
// Example of the BitConverter.GetBytes( uint ) method.
using System;

class GetBytesUInt32Demo
{
    const string formatter = "{0,16}{1,20}";

    // Convert a uint argument to a byte array and display it.
    public static void GetBytesUInt32( uint 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( uint ) " +
            "\nmethod generates the following output.\n" );
        Console.WriteLine( formatter, "uint", "byte array" );
        Console.WriteLine( formatter, "----", "----------" );

        // Convert uint values and display the results.
        GetBytesUInt32( 15 );
        GetBytesUInt32( 1023 );
        GetBytesUInt32( 0x100000 );
        GetBytesUInt32( 1000000000 );
        GetBytesUInt32( uint.MinValue );
        GetBytesUInt32( int.MaxValue );
        GetBytesUInt32( uint.MaxValue );
    }
}

/*
This example of the BitConverter.GetBytes( uint )
method generates the following output.

            uint          byte array
            ----          ----------
              15         0F-00-00-00
            1023         FF-03-00-00
         1048576         00-00-10-00
      1000000000         00-CA-9A-3B
               0         00-00-00-00
      2147483647         FF-FF-FF-7F
      4294967295         FF-FF-FF-FF
*/

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

GetBytes(UInt64)

Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs
Kaynak:
BitConverter.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen 64 bit işaretsiz tamsayı değerini bayt dizisi olarak döndürür.

C#
[System.CLSCompliant(false)]
public static byte[] GetBytes(ulong value);

Parametreler

value
UInt64

Dönüştürülecek sayı.

Döndürülenler

Byte[]

Uzunluğu 8 olan bayt dizisi.

Öznitelikler

Örnekler

Aşağıdaki kod örneği, UInt64 değerlerin bit desenlerini GetBytes yöntemiyle Byte dizilere dönüştürür.

C#
// Example of the BitConverter.GetBytes( ulong ) method.
using System;

class GetBytesUInt64Demo
{
    const string formatter = "{0,22}{1,30}";

    // Convert a ulong argument to a byte array and display it.
    public static void GetBytesUInt64( ulong 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( ulong ) " +
            "\nmethod generates the following output.\n" );
        Console.WriteLine( formatter, "ulong", "byte array" );
        Console.WriteLine( formatter, "-----", "----------" );

        // Convert ulong values and display the results.
        GetBytesUInt64( 0xFFFFFF );
        GetBytesUInt64( 1000000000 );
        GetBytesUInt64( 0x100000000 );
        GetBytesUInt64( 0xAAAAAAAAAAAA );
        GetBytesUInt64( 1000000000000000000 );
        GetBytesUInt64( 10000000000000000000 );
        GetBytesUInt64( ulong.MinValue );
        GetBytesUInt64( long.MaxValue );
        GetBytesUInt64( ulong.MaxValue );
    }
}

/*
This example of the BitConverter.GetBytes( ulong )
method generates the following output.

                 ulong                    byte array
                 -----                    ----------
              16777215       FF-FF-FF-00-00-00-00-00
            1000000000       00-CA-9A-3B-00-00-00-00
            4294967296       00-00-00-00-01-00-00-00
       187649984473770       AA-AA-AA-AA-AA-AA-00-00
   1000000000000000000       00-00-64-A7-B3-B6-E0-0D
  10000000000000000000       00-00-E8-89-04-23-C7-8A
                     0       00-00-00-00-00-00-00-00
   9223372036854775807       FF-FF-FF-FF-FF-FF-FF-7F
  18446744073709551615       FF-FF-FF-FF-FF-FF-FF-FF
*/

Açıklamalar

GetBytes yöntemi tarafından döndürülen dizideki baytların sırası, bilgisayar mimarisinin küçük endian mı yoksa büyük endian mı olduğuna bağlıdır.

Ayrıca bkz.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0