Let's look at the code. These are similar to your book, but better names. This does exactly what the equation dictates. Middle-square method uses bit shifting to arrive at a hash value. This gives us some nicely spread out hash values.
Lets look at some code.
The multiplication method is similar to the middle-square method. The difference is that instead of squaring the key value, you multiply it by a constant. The reason we don't want leading or trailing zeros is that if there is, collisions may occur more often then wanted. Above is some code which uses all three methods of hash functions. You are also going to have to try different sizes of M, and do some perfomance comparisons.