William John Holden
Some time ago I noticed an interesting property of binary arithmetic, described in my Math Tricks for IP Subnetting paper, where:
I wondered if such a rule could be applied for any radix. It seems intuitive:
Surprisingly, yes, this is very easily provable, and in binary this gives a very unique property.
The proof is trivial. For arbitrary radix r we hypothesize:
And verify using basic algebra:
Binary provides several unique properties given , which can be phrased in many ways:
Additional means to express this in spoken language that might suggest further applications.
This mathematical feature provides a very useful trick for computers: bit shifting. Bit shifting manifests in C-style programming languages as the << and >> operators. These two operators allow a programmer to shift bits to the left or right, which respectively raises or lowers the number by a factor of two equal to the number of shifts shifted.
To multiply an integer value by four, a programmer may use:
x << 2
To divide by sixteen, the programmer could write:
y >> 4
(Note that most programming languages will silently ignore overflows and loss of precision.)
IT professionals working in networking may also find this property useful when subnetting. Adding or removing a bit to a subnet mask will result in a network that is half or twice the original network size.
To divide a /24 network in half, simply extend the length of the subnet mask by one bit to /25. To divide into four subnets, make /24 into /26. CIDR notation makes this obvious, but it is not as apparent using dotted-decimal subnet masks.
I might add that this rule does not apply for Unary, where radix r is equal to one, because r-1=0. However, Unary does not have a means to express zero, thus this exception illustrates invalidity of Unary as a number system.