0
$\begingroup$

I am trying to learn about basic hashing using the modulo operator and am a bit confused. In the text that I am reading, it says that the modulo operator can be used to accept an input of any length and return a fixed-size output. However, take 1mod11 = 1 and 21mod11 = 10. The first equation yields a one-digit number and the second equation yields a two-digit number, how is it returning a fixed-sized output? Yes, a trivial question, but it's just not clicking for me - anyone care to explain?

$\endgroup$

1 Answer 1

2
$\begingroup$

Your example (using mod 11) is fixed-size in the number of digits because it will never be more than 2 digits. If you don't like having 1 or 2 digits, you can prefix the 1-digit number with leading 0s. If you took all the numbers mod 10, they'd all be 1 digit.

Other ways of thinking about it

The output can always be represented by $n$ or fewer digits.

The output is one of a finite set of values, e.g., 0, 1, 2, 3, ..., 10.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.