Hi, i'm need to calculate net mask and subnet addr using broadcast addr and host address from this subnet. I must use only bitwise operations not comparing of string representation, sysadmin tools and so on.
I have some formulas for calculating addresses. but i dont know, how using it with my source data.
- ^ -- is bitwise
xor
- ~ -- negation
- & and | conjunction and disjunction respectively
- Formulas:
- ip | (~m) = b
- ip & m = n
- n | (~m) = b
- n ^ b = ~m
where n -- is subnet address, b -- broadcast address, ip -- host address from subnet and m -- is net mask.
(for example, i have 192.168.1.160 -- subnet addr, 192.168.1.191 -- broadcast, and /27 net mask (255.255.255.224))
Thanks for advice, and excuse my english :)