math - How do I convert an IP address into an integer between 1 and 3? -


i'm not mathematician may stupid question...but - there way translate ip addresses integers between 1 , 3, whereby there a) equal distribution of 1's, 2's , 3's , b) each ip address translate same integer? (in essence, hash).

i'm using 3 example - ideally i'd range limit customizable.

 $highest_allowed_integer = 3; $integer = get_evenly_distributed_but_always_identical_integer($_server["remote_addr"],$highest_allowed_integer); 

thanks!

treat entire ipv4 address number in base 256 (that means 4.3.2.1 translate (4 << 24) + (3 << 16) + (2 << 8) + 1), mod 3, , add 1.

on little digression, might want concept of hashing.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -