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

# Go Left Shift Assignment

The `<<=` (left shift assignment) operator is a compound assignment statement in Go that performs a bitwise left shift on the left operand by the number of bit positions specified by the right operand, and subsequently assigns the computed result back to the left operand.

```go theme={"dark"}
x <<= y
```

In Go, `x <<= y` is a **statement**, not an expression. It does not evaluate to or return a value, and therefore cannot be embedded within other expressions.

While functionally similar to the expanded assignment `x = x << y`, the Go specification dictates that in a compound assignment, the left operand `x` is evaluated **exactly once**. This creates a significant semantic difference if `x` contains side effects. For example, the statement `arr[i()] <<= y` evaluates the function `i()` only once, whereas `arr[i()] = arr[i()] << y` would evaluate `i()` twice.

## Technical Mechanics

* **Operand Constraints:** The left operand (`x`) must be an assignable expression of an integer type (signed or unsigned). This includes addressable values (such as variables) as well as map index expressions (which are assignable but explicitly not addressable). The right operand (`y`), representing the shift count, must be of an integer type or an untyped constant representable by a value of type `uint` (such as the untyped floating-point constant `2.0`). If `y` is a constant, it must be non-negative. If `y` is evaluated at runtime and is negative, a runtime panic occurs.
* **Bit Manipulation:** The underlying `<<` operation shifts the binary representation of `x` to the left by `y` positions.
* **Zero Padding:** As bits are shifted to the left, the vacated bit positions on the right are padded with zeroes.
* **Truncation and Overflow:** Any bits shifted beyond the most significant bit (MSB) boundary of the left operand's specific bit-width (e.g., beyond the 8th bit in a `uint8`) are permanently discarded. For signed integers, shifting a `1` into the MSB will alter the sign of the value.

## Syntax Visualization

```go theme={"dark"}
package main

import "fmt"

func main() {
    var val uint8 = 5 // Binary representation: 00000101
    
    // Shift the bits of 'val' left by 3 positions and assign back to 'val'.
    // The right operand can be an untyped constant representable as a uint.
    val <<= 3.0         
    
    // The binary representation is now: 00101000
    // Decimal equivalent: 40
    fmt.Println(val) 
    
    // Example with a map index expression (assignable, but not addressable)
    m := map[string]int{"key": 2}
    m["key"] <<= 2 
    fmt.Println(m["key"]) // Outputs: 8
}
```

## Type Evaluation

The `<<=` operator does not alter the type of the left operand. The evaluation type of the underlying shift operation is strictly dictated by the type of the left operand. The statement updates `x` with a computed value of the exact same type as `x`, regardless of the type or magnitude of the shift count `y`.

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