[Tutor] print IP address range to stdout

MK lopoff at gmx.net
Wed Dec 23 11:14:43 CET 2009


Am Dienstag, den 22.12.2009, 19:09 +0100 schrieb spir:
> MK <lopoff at gmx.net> dixit:
> 
> > First function the ip is splitted as i did it. Alright.
> > The use 256 as it is the maximum for any digit. ok.
> > But what is that ** and exp meaning ????
> > 
> > ----------------------------------------------------------
> > def ip_to_int(dotted_ip):
> > 	exp = 3
> > 	intip = 0
> > 	for quad in dotted_ip.split('.'): 
> > 		intip = intip + (int(quad) * (256 ** exp))
> > 		exp = exp - 1
> > 	return(intip)
> > 	
> > ---------------------------------------------------
> 
> As a global explaination, this convert an ip address to a single integer, like if it were a number written in base 256 with 4 digits A,B,C,D:
>     aaa.bbb.ccc.ddd
> --> (A,B,C,D)
> --> A*(256^3) + B*(256^2) + C*(256^1) + D * (256^0)
> --> n
> 
> Denis
> ________________________________
> 
> la vita e estrany
> 
> http://spir.wikidot.com/

Ok. Thank you. I have something to learn. But now its clear. Like the
binarysystem with 2**n  etc. So to convert betweenn numbersystems i go
always this way.



More information about the Tutor mailing list