Byte Structure

Represents an 8-bit unsigned integer.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Structure Byte
	Implements IComparable, IFormattable, IConvertible, IComparable(Of Byte), _
	IEquatable(Of Byte)
Dim instance As Byte

/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class Byte extends ValueType implements IComparable, IFormattable, 
	IConvertible, IComparable<byte>, IEquatable<byte>
JScript suports the use of structures, but not the declaration of new ones.

The Byte value type represents unsigned integers with values ranging from 0 to 255.

Byte provides methods to compare instances of this type, convert the value of an instance to its string representation, and convert the string representation of a number to an instance of this type.

For information about how format specification codes control the string representation of value types, see Formatting Overview.

This type implements interfaces IComparable, IComparable, IFormattable, and IConvertible. Use the Convert class for conversions instead of this type's explicit interface member implementation of IConvertible.

This type is thread safe; multiple threads can concurrently read from an instance of this type.

The following example demonstrates the use of Byte when converting an array of bytes into a string of hexadecimal values.

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}

   End Sub 'Main

End Class 'HexTest

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(
            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 };
    } //main
} //HexTest

This type is safe for multithreaded operations.

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions