R
robert
I'm following Roedy's code here:
http://mindprod.com/jgloss/ip.html#DISPLAYING
IP bit manipulation tricks
// IP bit tricks
// compute an n bit subnet mask, all 1s except for last n bits.
int subnet = ~( ( 1 << n ) - 1 );
// generate a list of possible local IP addresses, e.g.
// 192.168.0.0 .. 192.168.255.255
int base = (192 << 24) | (168 << 16);
for ( int i=0; i<0xffff; i++ )
{
int sample = base | i;
System.out.println( DottedQuad.dottedQuad( sample ) );
}
What I need is to pass an IP - say 192.168.10.10 - and a subnet for
example 255.255.255.0 - and get a list of IP's . I do know binary a
bit, yet it looks like he's putting a hex value in the for loop, and
I'm not sure how to calculate it. Should I do:
int subnet = ~( ( 1 << n ) - 1 );
Where n == 255.255.255.0 and use the 'int subnet' as the value in the
for loop ? And how do I calculate the '192 << 24' and the '168 << 16'
in the 'base' equation , ie, just strip and always use 16 and 24 ?
Robert
http://mindprod.com/jgloss/ip.html#DISPLAYING
IP bit manipulation tricks
// IP bit tricks
// compute an n bit subnet mask, all 1s except for last n bits.
int subnet = ~( ( 1 << n ) - 1 );
// generate a list of possible local IP addresses, e.g.
// 192.168.0.0 .. 192.168.255.255
int base = (192 << 24) | (168 << 16);
for ( int i=0; i<0xffff; i++ )
{
int sample = base | i;
System.out.println( DottedQuad.dottedQuad( sample ) );
}
What I need is to pass an IP - say 192.168.10.10 - and a subnet for
example 255.255.255.0 - and get a list of IP's . I do know binary a
bit, yet it looks like he's putting a hex value in the for loop, and
I'm not sure how to calculate it. Should I do:
int subnet = ~( ( 1 << n ) - 1 );
Where n == 255.255.255.0 and use the 'int subnet' as the value in the
for loop ? And how do I calculate the '192 << 24' and the '168 << 16'
in the 'base' equation , ie, just strip and always use 16 and 24 ?
Robert