다음을 통해 공유


Byte 구조체

부호 없는 8비트 정수를 나타냅니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Structure Byte
    Implements IComparable, IFormattable, IConvertible, IComparable(Of Byte), _
    IEquatable(Of Byte)
‘사용 방법
Dim instance As 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, IFormattableIConvertible 인터페이스를 구현합니다. 변환을 위해 이 형식의 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

스레드로부터의 안전성

이 형식은 다중 스레드 작업을 수행하는 데 안전합니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Byte 멤버
System 네임스페이스
SByte
String
IComparable
IFormattable
IConvertible