so I have this code... which seems long and cumbersome, and not all that fun to type out, and so far I have thought of using tables to get things up and running, but I wanted to see if anyone had something better it would go something like this
I am trying to find the bits borrowed out of an ip address and the bits remaining
Code:
void bitsborrowed(int ip[], int subnet[], char addressclass, int *bitsborrowed, int *bitsremaning)
{
if(addressclass == 'c')
{
//for class c use the last octet
if(subnet[3] == 252)
{
*bitsremaining = 2;
*bitsborrowed = 6;
}
else if(subnet[3] == 248)
{
*bitsremaining = 3;
*bitsborrowed = 5;
}
//etc...
if(addressclass == 'b')
{
if(subnet[3] === 252 && subnet[2] == 255)
{
*bitsremaining = 2;
*bitsborrowed = 14;
}
// and so forth...
as you can see there are a lot of cases to check... any help would be great, thanks!