<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UInt8/_=(_:_:)-12hmo",
  "metadataVersion" : "0.1.0",
  "role" : "Operator",
  "symbol" : {
    "kind" : "Operator",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s5UInt8V2reoiyyABz_ABtFZ"
  },
  "title" : "%=(_:_:)"
}
-->

# %=(_:_:)

Divides the first value by the second and stores the remainder in the
left-hand-side variable.

```
static func %= (lhs: inout UInt8, rhs: UInt8)
```

## Parameters

`lhs`

The value to divide.

`rhs`

The value to divide `lhs` by. `rhs` must not be zero.

## Discussion

The result has the same sign as `lhs` and has a magnitude less than
`rhs.magnitude`.

```
var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)