> ## 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 Bitwise AND Assignment

The `&=` operator is a compound assignment operator that performs a bitwise AND operation between the left and right operands, subsequently assigning the resulting value to the left operand. It serves as a syntactic shorthand, meaning `x &= y` is strictly equivalent to `x = x & y`, with the exception that the left operand `x` is evaluated only once.

```go theme={"dark"}
variable &= expression
```

## Technical Mechanics

1. **Type Constraints:** Both operands must resolve to integer types (e.g., `int`, `uint8`, `int64`) or untyped constants representable as integers. Go does not permit bitwise operations on floating-point numbers or complex types.
2. **Bit-by-Bit Evaluation:** The operator aligns the binary representations of both operands and evaluates them bit by bit.
3. **Truth Logic:** For each corresponding bit position, the resulting bit is set to `1` if and only if both the left and right bits are `1`. Otherwise, the resulting bit is set to `0`.

**Bitwise AND Truth Table:**

* `1 & 1 = 1`
* `1 & 0 = 0`
* `0 & 1 = 0`
* `0 & 0 = 0`

## Code Example

The following example demonstrates the binary transformation that occurs when the `&=` operator is applied.

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

import "fmt"

func main() {
    var a uint8 = 12 // Binary representation: 0000 1100
    var b uint8 = 10 // Binary representation: 0000 1010

    // Perform bitwise AND and assign the result to 'a'
    a &= b 

    // Calculation breakdown:
    //   0000 1100  (12)
    // & 0000 1010  (10)
    // --------
    //   0000 1000  (8)

    fmt.Printf("Decimal: %d | Binary: %08b\n", a, a)
    // Output: Decimal: 8 | Binary: 00001000
}
```

## Evaluation Order

In the expression `a[i()] &= b()`, the function `i()` is evaluated exactly once to determine the index of the slice or array, followed by the evaluation of `b()`. The bitwise AND is then calculated, and the result is written back to the memory address resolved by `a[i()]`.

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