Byte 構造体とは? わかりやすく解説

Byte 構造体

8 ビット符号なし整数表します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Structure Byte
    Implements IComparable, IFormattable, IConvertible, IComparable(Of
 Byte), _
    IEquatable(Of Byte)
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public struct Byte : IComparable, IFormattable, IConvertible,
 
    IComparable<byte>, IEquatable<byte>
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public value class Byte : IComparable, IFormattable,
 IConvertible, 
    IComparable<unsigned char>, IEquatable<unsigned char>
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class Byte extends ValueType implements
 IComparable, IFormattable, 
    IConvertible, IComparable<byte>, IEquatable<byte>
JScript では、構造体使用できますが、新規に宣言することはできません。
解説解説

Byte 値型は、値が 0 から 255 までの範囲符号なし整数表します

Byte は、この型のインスタンス比較したり、インスタンスの値を文字列形式変換したり、数値文字列形式をこの型のインスタンス変換するためのメソッド提供します

書式指定コード値型文字列形式制御する方法については、「書式設定概要」を参照してください

この型は、IComparable、IComparable、IFormattable、IConvertible の各インターフェイス実装ます。この型の明示的な IConvertible インターフェイス メンバ実装代わりにConvert クラス使用します

この型はスレッドセーフであり、複数スレッド同時にこの型のインスタンスか読み込むことができます

使用例使用例

バイト配列16 進値で表現した文字列変換する際の Byte使用例次に示します

Class HexTest

   Private Shared hexDigits As
 Char() =  {"0"c, "1"c,
 "2"c, "3"c, "4"c, "5"c, "6"c,
 "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
   
   Public Shared Function
 ToHexString(bytes() As Byte) As
 String

      Dim hexStr As String
 = ""
      Dim i As Integer
      For i = 0 To bytes.Length - 1
     hexStr = hexStr + Hex(bytes(i))
      Next i
      Return hexStr 

   End Function 'ToHexString

  
   Shared Sub Main()
      
      Dim b As Byte() =
  {&H0, &H12, &H34, &H56, &HAA, &H55, &HFF}
      Console.WriteLine(ToHexString(b))

   End Sub 'Main

End Class 'HexTest

class HexTest
{
    static char[] hexDigits = {
        '0', '1', '2', '3', '4', '5', '6', '7',
        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
 
    public static string
 ToHexString(byte[] bytes) {
        char[] chars = new char[bytes.Length
 * 2];
        for (int i = 0; i < bytes.Length;
 i++) {
            int b = bytes[i];
            chars[i * 2] = hexDigits[b >> 4];
            chars[i * 2 + 1] = hexDigits[b & 0xF];
        }
        return new string(chars);
    }
 
    static void Main() {

        byte[] b = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF};
        Console.WriteLine(ToHexString(b));
    }
}

ref class HexTest
{
private:
   static array<Char>^hexDigits = {'0','1','2','3','4','5'
,'6','7','8','9','A','B','C','D','E','F'};

public:
   static String^ ToHexString( array<Byte>^bytes )
   {
      array<Char>^chars = gcnew array<Char>(bytes->Length * 2);
      for ( int i = 0; i < bytes->Length;
 i++ )
      {
         int b = bytes[ i ];
         chars[ i * 2 ] = hexDigits[ b >> 4 ];
         chars[ i * 2 + 1 ] = hexDigits[ b & 0xF ];

      }
      return gcnew String( chars );
   }

};

int main()
{
   array<Byte>^b = {0x00,0x12,0x34,0x56,0xAA,0x55,0xFF};
   Console::WriteLine( HexTest::ToHexString( b ) );
}

class HexTest
{
    private static char
 hexDigits[] =  { '0', '1', '2', '3', '4', '5', 
        '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

    public static String ToHexString(ubyte
 bytes[])
    {
        char chars[] = new char[bytes.get_Length()
 * 2];
        for (int i = 0; i < bytes.get_Length();
 i++) {
            int b = System.Convert.ToInt32(
                System.Convert.ToString(bytes.get_Item(i)));
            chars.set_Item((i * 2), hexDigits.get_Item(b >> 4));
            chars.set_Item((i * 2 + 1), hexDigits.get_Item(b & 0xF));
        }
        return new String(chars);
    } //ToHexString

    public static void main(String[]
 args)
    {
        ubyte b[] =  { 0x0, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF };
        Console.WriteLine(ToHexString(b));
    } //main
} //HexTest
スレッド セーフスレッド セーフ

この型は、マルチスレッド操作に対して安全です。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Byte メンバ
System 名前空間
SByte
String
IComparable
IFormattable
IConvertible



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Byte 構造体」の関連用語

Byte 構造体のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Byte 構造体のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS