Mod (modulo or redundancy)

Source: Internet
Author: User

1. Residual: The remainder after the division is divided, for example:

MOD 4 = 2;   -17 MOD 4 =-1;    -3 MOD 4 =-3;    4 MOD (-3) = 1; -4 MOD 3 =-1;

If a mod B is an XOR, then the resulting symbol is the same as a; Of course, a mod B is equivalent to a-(a DIV b) *b operation. For example:

MOD 4 =-(4 DIV.) * 4 = 13-12 = 1

(XOR rule: A% B = C, the value of C is: | a| % | b| results, let the result be the same as a, and then add to B. For example: |-15| % |4| = 3,

Then-3 + 4 = 1, if it is 15 (-4), then the result is 3 + (-4) =-1, note that must be two number of different numbers is the rule, the same number is the same as the general algorithm)

2. Modulo: "A MOD B" can not be negative, and its operation rules are as follows:

1) When a > B, continuously subtract b from a, until a non-negative number less than B is present.

Example: 8 MOD 3 = 2

2) When a < B, and a > 0 o'clock, the result is a.

Example: 3 MOD 8 = 3

3) When a < B, and a < 0 o'clock, B is continuously added to a, until the result is a non-negative number less than B.

Example:-3 mod 4 = 1,-4 mod 3 = 2

Note: When A and B are all positive, the results are the same, whether it is "seeking redundancy" or "seeking for a model". such as: MOD 6 = 4, only when a < 0 o'clock, the results of the two operations


For example: N is four digits 7341, you can use the following method to isolate its, ten, hundred, thousands.

7431 MOD 10 = 1 (single digit)

(7431 MOD 100) DIV 10 = 4 (10-digit)

(7431 MOD 1000) DIV 100 = 3 (hundred numbers)

7431 DIV 1000 = 7 (Thousand numbers)

Also, using a MOD B, you can tell if a can be divisible by B. When a MOD b = 0 o'clock, a can be divisible by B.

Note: A and B must be integers. For example: 50.0 MOD 20.0 is not possible.

Note: The mold can be regarded as positioning, such as%10 positioning to bits,%100 positioning to the hundred. The div can be seen as the number of bits to be determined.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.