How Does Modulus Divison Work

后端 未结 19 1928
栀梦
栀梦 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:13

    Write out a table starting with 0.

    {0,1,2,3,4}
    

    Continue the table in rows.

    {0,1,2,3,4}
    {5,6,7,8,9}
    {10,11,12,13,14}
    

    Everything in column one is a multiple of 5. Everything in column 2 is a multiple of 5 with 1 as a remainder. Now the abstract part: You can write that (1) as 1/5 or as a decimal expansion. The modulus operator returns only the column, or in another way of thinking, it returns the remainder on long division. You are dealing in modulo(5). Different modulus, different table. Think of a Hash Table.

提交回复
热议问题