Q:

How to extract the p MSB bits of a given number

Ok so I'm implementing a hash function that utilizes the multiplication method. 
I have been given a K and a S (where S = A * 2^word). I have found my p and all I need to do is to extract the p most significant bits from the product of KS. So let's say KS = 51 which is represented as 110011 in binary and p = 4; I'd need to extract the 4 most significant bits i.e. 1100 or 12 and that would in theory be h(k) for a multiplication hash function!
How may I go about doing so? 
A simple 
int tempHold = k * s;
tempHold << p; 

is not working.

A:

You could take the floor of the log base 2 of said number to get the number of bits, N, in the number, then perform a rightshift (>>) by (N -p). This would leave behind the p most significant bits.

