How Does Modulus Divison Work

后端 未结 19 1917
栀梦
栀梦 2020-11-22 06:55

I don\'t really understand how modulus division works. I was calculating 27 % 16 and wound up with 11 and I don\'t understand why.

I can\'t

19条回答
  •  日久生厌
    2020-11-22 07:11

    The simple formula for calculating modulus is :-

    [Dividend-{(Dividend/Divisor)*Divisor}]
    

    So, 27 % 16 :-

    27- {(27/16)*16}

    27-{1*16}

    Answer= 11

    Note:

    All calculations are with integers. In case of a decimal quotient, the part after the decimal is to be ignored/truncated.

    eg: 27/16= 1.6875 is to be taken as just 1 in the above mentioned formula. 0.6875 is ignored.

    Compilers of computer languages treat an integer with decimal part the same way (by truncating after the decimal) as well

提交回复
热议问题