PHP Code:
$ip=sprintf("%u",ip2long($vbulletin->GPC['ip']));
Makes the $ip a string with a max value of 2147483647*2. Then when PHP needs to do arithmetic on the string it implicitly casts it to a float if it is larger then 2147483647 (for 32-bit systems) otherwise an int. On 64-bit systems PHP expands integers to 2^64.
Right, I had already figured out the problem. I removed the sprintf and allowed the AND to be done with the integers then printed it as an unsigned int in the query.
Your solution works perfectly.