> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# byte

The `byte` keyword in C# represents an 8-bit unsigned integer. It is an alias for the .NET `System.Byte` structure and is used to store positive numeric values ranging from 0 to 255. As a value type, it is allocated directly on the stack (or inline within an object) and has a default value of `0`.

## Technical Specifications

* **.NET Type:** `System.Byte`
* **Memory Size:** 8 bits (1 byte)
* **Minimum Value:** `0` (`byte.MinValue`)
* **Maximum Value:** `255` (`byte.MaxValue`)
* **Sign:** Unsigned (cannot represent negative numbers)

## Declaration and Initialization

You can initialize a `byte` using standard decimal literals, hexadecimal literals, or binary literals.

```csharp theme={"dark"}
byte decimalByte = 200;
byte hexByte = 0xC8;        // Hexadecimal equivalent of 200
byte binaryByte = 0b11001000; // Binary equivalent of 200

byte min = byte.MinValue;   // 0
byte max = byte.MaxValue;   // 255
```

## Type Conversions

Because `byte` is the smallest unsigned integer type in C#, its conversion rules are strictly defined to prevent unintended data loss.

**Implicit Conversions**
A `byte` can be implicitly converted to any larger numeric type or any floating-point type: `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `float`, `double`, or `decimal`.

```csharp theme={"dark"}
byte b = 128;
int i = b;       // Implicit conversion to 32-bit signed integer
double d = b;    // Implicit conversion to 64-bit floating point
```

**Explicit Conversions**
Converting from a larger integer type, a floating-point type, or a signed type (like `sbyte`) to a `byte` requires an explicit cast.

```csharp theme={"dark"}
int largeInt = 200;
byte b1 = (byte)largeInt; // Explicit cast required

sbyte signedByte = 50;
byte b2 = (byte)signedByte; // Explicit cast required due to sign difference
```

## Overflow Behavior

When a mathematical operation causes a `byte` to exceed its maximum value (255) or drop below its minimum value (0), the behavior depends on the compiler's overflow checking context.

```csharp theme={"dark"}
byte b = 255;

unchecked
{
    b++; // Silently wraps around to 0
}

checked
{
    // b++; // Throws System.OverflowException at runtime
}
```

## Bitwise Operations and Numeric Promotion

When performing arithmetic or bitwise operations (`~`, `&`, `|`, `^`, `<<`, `>>`) on `byte` operands, C# implicitly promotes the operands to `int` (32-bit) before evaluating the expression. The result of the operation is an `int`, which must be explicitly cast back to a `byte` if you intend to store it in a `byte` variable.

```csharp theme={"dark"}
byte b1 = 0b_1010_0000;
byte b2 = 0b_0000_1111;

// b1 | b2 evaluates to an Int32. Explicit cast is mandatory.
byte result = (byte)(b1 | b2); 

// Bitwise complement also results in an Int32
byte complement = (byte)(~b1); 
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
