> ## 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.

# Dart Left Shift

The `<<` (bitwise left shift) operator shifts the binary representation of an integer to the left by a specified number of bit positions. As the bits are shifted left, the high-order (leftmost) bits are discarded, and zero bits are shifted in from the right to fill the vacated low-order positions.

```dart theme={"dark"}
int result = target << shiftAmount;
```

## Operands

* **`target`**: The base `int` whose bits are being manipulated.
* **`shiftAmount`**: A non-negative `int` dictating the number of bit positions to shift. If this value is negative, Dart throws an `ArgumentError`.

## Mechanics

Dart integers are 64-bit two's complement numbers on native platforms. The `<<` operator performs a logical left shift on this 64-bit sequence.

Mathematically, evaluating `a << b` is equivalent to multiplying `a` by $2^b$, provided the operation does not result in an overflow beyond the integer limit of the underlying platform.

## Syntax Visualization

**Positive Integer Shift:**

```dart theme={"dark"}
int a = 5;       // 64-bit Binary: 00000000 ... 00000101
int b = a << 3;  // 64-bit Binary: 00000000 ... 00101000

print(b);        // Output: 40 (which is 5 * 2^3)
```

**Negative Integer Shift (Two's Complement):**

```dart theme={"dark"}
int x = -3;      // 64-bit Binary: 11111111 ... 11111101
int y = x << 2;  // 64-bit Binary: 11111111 ... 11110100

print(y);        // Output: -12 (which is -3 * 2^2)
```

## Platform Specifics

Because Dart compiles to both native machine code and JavaScript, the behavior of `<<` diverges based on the compilation target:

* **Dart Native (VM/AOT):** Operates on 64-bit two's complement integers. High-order bits are discarded only when they exceed the 64th bit. Shifting by 32 performs a literal 32-bit shift.
* **Dart Web (JavaScript):** JavaScript bitwise operations implicitly convert operands to 32-bit signed integers. This introduces three critical behavioral differences:
  1. **Target Truncation:** The `target` is truncated to 32 bits before the shift occurs.
  2. **Shift Amount Masking:** The `shiftAmount` is masked to 5 bits (modulo 32). Consequently, shifting by 32 on the web results in a shift of 0 (returning the original number unmodified), whereas native platforms shift by the full 32 positions.
  3. **Result Constraint:** The final result of the shift is constrained to a 32-bit signed integer. This alters the result even for small targets if the shifted value exceeds 31 bits. For example, `1 << 31` evaluates to `2147483648` on native platforms, but wraps to `-2147483648` on the web due to 32-bit signed integer overflow.

<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 Dart 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>
