Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Byte Structure

Represents an 8-bit unsigned integer.

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

public struct Byte : IComparable, IFormattable, IConvertible, 
	IComparable<byte>, IEquatable<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
    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};

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

© 2017 Microsoft