Re: how to specify power of number
- From: "Bartc" <bc@xxxxxxxxxx>
- Date: Fri, 18 Apr 2008 11:01:49 GMT
"Yanb" <Yanb@xxxxxxxxxxxxxxxx> wrote in message
news:fu9q89$kem$1@xxxxxxxxxxx
Hi, I'm new to c, so please excuse, if this is silly ;-)
I made a C function, which takes IP adress from string and converts to
unsigned long int. Everything
works, but I found that the "counting" part part works only with this:
numericip=atoi(textip[0])*256*256*256+atoi(textip[1])*256*256+atoi(textip[2])*256+atoi(textip[3]);
When I wrote *(256^3), I got fake results. I'd like to use something more
sophisticated, instead of 256*256
*256, which does look silly ;-) (Just curious, what if I'd ever need to
make 100th power of 256 ;-) )
You would have to use pow(256,3) which uses floating point arithmetic -- not
recommended, even though the compiler is likely to optimise.
Your code is fine as it is, the compiler will optimise 256*256*256 to
*16777216 or <<24. Or just write those in yourself.
--
Bart
.
- Follow-Ups:
- Re: how to specify power of number
- From: Antoninus Twink
- Re: how to specify power of number
- References:
- how to specify power of number
- From: Yanb
- how to specify power of number
- Prev by Date: Re: Problem in writing structure to Binary file in C lang
- Next by Date: Re: How to eliminate this global variable, silent?
- Previous by thread: Re: how to specify power of number
- Next by thread: Re: how to specify power of number
- Index(es):
Relevant Pages
|