Minor changes are by default collapsed in the page history.
No changes
The page does not exist yet.
Failed to load changes
Version by on
Leave Collaboration
Are you sure you want to leave the realtime collaboration and continue editing alone? The changes you save while editing alone will lead to merge conflicts with the changes auto-saved by the realtime editing session.
C Programming Modulus Operator %
Last modified by Microchip on 2023/11/09 09:06
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 just the lower n-bits of x
2. Can be used to break apart a number in any base into its individual digits
Example
1 2 3 4 5 6 7 8 9 10
#define MAX_DIGITS 6 long number =123456; int i, radix =10; char digits[MAX_DIGITS];
for (i =0; i < MAX_DIGITS; i++) { if (number ==0) break; digits[i] = (char)(number % radix); number /= radix; }
If you need to work with Microchip Support staff directly, you can submit a technical support case. Keep in mind that many questions can be answered through our self-help resources, so this may not be your speediest option.