英語で読む

次の方法で共有


BitConverter.ToUInt32 メソッド

定義

オーバーロード

ToUInt32(ReadOnlySpan<Byte>)

読み取り専用のバイト スパンを 32 ビット符号なし整数に変換します。

ToUInt32(Byte[], Int32)

バイト配列内の指定位置にある 4 バイトから変換された 32 ビット符号なし整数を返します。

ToUInt32(ReadOnlySpan<Byte>)

ソース:
BitConverter.cs
ソース:
BitConverter.cs
ソース:
BitConverter.cs

重要

この API は CLS 準拠ではありません。

読み取り専用のバイト スパンを 32 ビット符号なし整数に変換します。

C#
[System.CLSCompliant(false)]
public static uint ToUInt32(ReadOnlySpan<byte> value);

パラメーター

value
ReadOnlySpan<Byte>

変換するバイトを含む読み取り専用のスパン。

戻り値

変換されたバイトを表す 32 ビット符号なし整数。

属性

例外

value の長さは 4 未満です。

適用対象

.NET 10 およびその他のバージョン
製品 バージョン
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

ToUInt32(Byte[], Int32)

ソース:
BitConverter.cs
ソース:
BitConverter.cs
ソース:
BitConverter.cs

重要

この API は CLS 準拠ではありません。

バイト配列内の指定位置にある 4 バイトから変換された 32 ビット符号なし整数を返します。

C#
[System.CLSCompliant(false)]
public static uint ToUInt32(byte[] value, int startIndex);

パラメーター

value
Byte[]

バイト配列。

startIndex
Int32

value 内の開始位置。

戻り値

startIndex から始まる 4 バイトで構成される 32 ビット符号なし整数。

属性

例外

startIndexvalue の長さから 3 を引いた値以上で、value の長さから 1 を引いた値以下です。

valuenullです。

startIndex が 0 未満か、value の長さから 1 を引いた値より大きい値です。

次のコード例では、 メソッドを使用して配列のByte要素を値にUInt32ToUInt32変換します。

C#
// Example of the BitConverter.ToUInt32 method.
using System;

class BytesToUInt32Demo
{
    const string formatter = "{0,5}{1,17}{2,15}";

    // Convert four byte array elements to a uint and display it.
    public static void BAToUInt32( byte[ ] bytes, int index )
    {
        uint value = BitConverter.ToUInt32( bytes, index );

        Console.WriteLine( formatter, index,
            BitConverter.ToString( bytes, index, 4 ), value );
    }

    public static void Main( )
    {
        byte[ ] byteArray = {
             15,   0,   0,   0,   0,  16,   0, 255,   3,   0,
              0, 202, 154,  59, 255, 255, 255, 255, 127 };

        Console.WriteLine(
            "This example of the BitConverter.ToUInt32( byte[ ], " +
            "int ) \nmethod generates the following output. It " +
            "converts elements \nof a byte array to uint values.\n" );
        Console.WriteLine( "initial byte array" );
        Console.WriteLine( "------------------" );
        Console.WriteLine( BitConverter.ToString( byteArray ) );
        Console.WriteLine( );
        Console.WriteLine( formatter, "index", "array elements",
            "uint" );
        Console.WriteLine( formatter, "-----", "--------------",
            "----" );

        // Convert byte array elements to uint values.
        BAToUInt32( byteArray, 1 );
        BAToUInt32( byteArray, 0 );
        BAToUInt32( byteArray, 7 );
        BAToUInt32( byteArray, 3 );
        BAToUInt32( byteArray, 10 );
        BAToUInt32( byteArray, 15 );
        BAToUInt32( byteArray, 14 );
    }
}

/*
This example of the BitConverter.ToUInt32( byte[ ], int )
method generates the following output. It converts elements
of a byte array to uint values.

initial byte array
------------------
0F-00-00-00-00-10-00-FF-03-00-00-CA-9A-3B-FF-FF-FF-FF-7F

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

注釈

メソッドは ToUInt32 、バイトをインデックス startIndex から + 3 に startIndex 値に UInt32 変換します。 配列内のバイト数は、コンピューター システムのアーキテクチャのエンディアンを反映している必要があります。 詳細については、クラス トピックの「解説」セクションを BitConverter 参照してください。

こちらもご覧ください

適用対象

.NET 10 およびその他のバージョン
製品 バージョン
.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