Hey there, I've modified your calcSubnet() function to use the proper decimal representation for "all bits set to 1". I didn't like the use of the number you provided, as I couldn't find a reason (except for, maybe it just worked that way) to use '4294967295'.
Maybe you can provide some insight into why your code was written the way it was?
I feel like mine is still a little sloppy, but I'm still learning quite a lot, so I'm keen to see what you think
cidr = 16
def calcSubnet(cidr):
#Cidr into Subnet
Bits2Zero = 32-cidr #How many bits we'll need to zero
Bits2Decimal = 2**Bits2Zero #The calculation of bits into a decimal
AllBits = 2**32 #All bits in a IPv4 Address
#Convert it
Subnet = AllBits - Bits2Decimal #Decimal Representation of the subnet address
Subnet = calcIPNotation(Subnet) #Pass the decimal subnet into the function
print Subnet #Print the subnet adress
calcSubnet(cidr)
And I just made it better
cidr = 29
def calcSubnet(cidr):
DecimalSubnet = ( (2**32) - (2**(32-cidr)) )
Subnet = calcIPNotation(DecimalSubnet)
return Subnet
InverseSubnet = ~DecimalSubnet
Inverse = calcIPNotation(InverseSubnet)
return Inverse
calcSubnet(cidr)