C: translate int_32 to 8-bit
Jan 25, 2009 at 5:52am UTC
hello,
So, if I converting ip address from 8-bit to int_32 type.
address = (((((ip[0]<<8)+ip[1])<<8)+ip[2])<<8)+ip[3];
But, which's way reverse that?
I tried this way
1 2
for (;i<4; ++i) id[i] = (address >> (i*8)) & 0xFF;
printf("%u\n" , id[i]);
However. I've got a value prefix where has been that ip-address.
How to do converting value from int_32 to 8-bit?
Jan 25, 2009 at 6:01am UTC
id[3-i]=...
Jan 25, 2009 at 7:34am UTC
Hm, I think what it's mistake, see to that...
If I doing whatever like this
1 2 3 4 5
for (address=first_address; address<first_address+hosts; ++address){
printf("%u\n\n" , address);
for (;i<3; i++) id[i] = (address >> (i*8)) & 0xFF;
printf("%u\n" , id[i]);
}
I've got it crazy of result
1 2 3 4 5 6 7 8 9 10 11 12
3232240640
0
3232240641
0
3232240642
0
3232240643
0
But I expect something like this
1 2 3 4 5 6 7 8
3232240640
192.168.20.0
3232240641
192.168.20.1
3232240642
192.168.20.2
3232240643
192.168.20.3
Last edited on Jan 25, 2009 at 7:45am UTC
Topic archived. No new replies allowed.