Modulus Operator

Applications of the Modulus Operator

1. Truncation: x % 2n where n is the desired word width (e.g. 8 for 8 bits: x % 256).

  • Returns the value of the lower n-bits of x

2. Can be used to break apart a number (in any base) into its individual digits.

Example