Introduction
Prefix boundaries, wildcard masks and address ranges become easier to verify when you can reproduce one octet by hand. Work with an explicit bit width, then extend the same operations to a whole address.
Formula and calculation
decimal value = Σ bit[i] × 2^iEach binary position contributes its power-of-two place value when the bit is 1. Address conversion preserves a fixed-width bit pattern even when leading zeroes are omitted in an integer display.
- bit[i] · bit
- 0 or 1 at position i, counted from the right
Use place values and fixed width
Write the eight weights of an octet from 128 down to 1. Reading a binary number means adding the weights whose digits equal one. Leading zeroes keep the positions aligned when one value is drawn above another.
Hexadecimal groups four bits into each digit, giving two digits per octet. The byte 10101101 splits into 1010 and 1101, or AD. Choosing a different base alters how the number is written while preserving its place in the address space.
Use AND to keep a field and OR to set it
At each position, AND produces one only when both operands have one. A subnet mask uses this rule to keep the prefix bits and clear the host bits. OR produces one when either input has one, so it can set the host field to all ones.
XOR produces one where the operand bits differ. XOR two addresses and inspect the most significant differing bit to locate the first position where their shared prefix ends. Equal addresses produce an all-zero difference.
Separate addition from bit operations
Binary addition can carry into the next position. OR cannot. For example, 00000111 + 00000001 gives 00001000 while their bitwise OR gives 00000111. A carry beyond the selected width requires an explicit overflow policy.
Complement also requires a width. For an eight-bit value x, the bounded complement is 255 XOR x. This keeps the answer within one octet. To complement an IPv4 mask, apply the same operation across 32 bits.
Diagram
- Host octet · 10101101
- AND mask · 11100000
- Network · 10100000
- OR wildcard · 10111111
Worked examples
Check the fourth octet of 192.0.2.173/27
- Decompose 173 into 128 + 32 + 8 + 4 + 1, giving 10101101. The fourth mask byte for /27 is 11100000, or 224.
- AND the two bytes to get 10100000, or 160. Complement 11100000 within eight bits to get wildcard 00011111, or 31.
- OR 10100000 with 00011111 to get 10111111, or 191. Count inclusively: 191 − 160 + 1 = 32, which matches 2^5 host-field patterns.
Binary Calculator: Pack 45 items into groups of six
- Write 45 as 101101 using the weights 32 + 8 + 4 + 1. Six is 110.
- Divide 101101 by 110. The whole quotient is 111 and the remainder is 11.
- Check in decimal. Seven full groups take 42 items and leave three. An eighth group would require 48.
Reference table
| Operation | Eight-bit expression | Decimal result |
|---|---|---|
| AND | 10101101 AND 11100000 | 160 |
| Bounded NOT | NOT 11100000 | 31 |
| OR | 10100000 OR 00011111 | 191 |
| XOR | 10101101 XOR 10100000 | 13 |
Configuration example
- Word width = 8 bits for each octet calculation
- Address octet = 10101101
- Network mask octet = 11100000
- Host mask octet = 00011111
Common mistakes
- Moving the leftmost one to the right when padding binary output. Pad with zeroes on the left.
- Using floating-point logarithms or signed 32-bit operations for an exact 128-bit IPv6 value.
Frequently asked questions
How do shifts relate to multiplication?
For an unsigned integer, shifting left one place multiplies it by two if the result still fits. A fixed-width register can lose its top bit on overflow.
Why does 255 + 1 become 256 on paper?
The exact sum has nine bits, 100000000. An eight-bit register needs an overflow indication or a defined wrapping rule to represent that operation.
Why do binary place values double from right to left?
Binary is base two. Each position is one power of two, so moving one place left multiplies its value by two.
How many bits are in a byte?
A byte contains eight bits. The byte can represent 256 distinct patterns, from 00000000 through 11111111.
Why is a subnet mask useful in binary?
A bitwise AND between an address and a contiguous mask preserves prefix bits and clears host bits, producing the network address.
Can hexadecimal shorten an IPv6 address without changing its value?
Yes. Hexadecimal groups four bits per digit, so it is a compact way to display 128-bit values. Zero compression changes notation, not the address bits.
What does two's complement do?
It is a common fixed-width representation for signed integers. The same bit pattern has a different interpretation depending on whether it is treated as signed or unsigned.
What does a bitwise AND do to a mask and address?
Each output bit is one only where both corresponding input bits are one. With a contiguous subnet mask, this preserves the prefix bits and clears host bits.
Why must a bitwise operation specify width?
Fixed-width operations constrain results to a chosen number of bits. Without a width, leading zeroes and overflow behavior can differ between mathematical integers and machine values.
How many bits does one hexadecimal digit represent?
One hexadecimal digit represents four binary bits. Two hex digits make one byte, which is why IPv6 hextets and MAC octets are naturally written in hex.
How do I convert a small binary number to decimal?
Multiply each bit by its power-of-two place value and add the results. For example, 10110₂ is 16 + 4 + 2 = 22₁₀.
Why group binary digits into fours when writing hexadecimal?
Each hex digit maps exactly to four bits. Grouping bits this way makes long address values shorter while preserving the exact bit pattern.
What is the difference between a signed and unsigned integer?
An unsigned fixed-width value treats all bits as magnitude. A signed representation reserves patterns for negative values, often using two's complement, so the same bit string can have a different decimal interpretation.
Does integer overflow wrap automatically in every calculator?
No. Behavior depends on the implementation and chosen width. A fixed-width calculator may reject an overflow, wrap, or report a carry, so inspect its documented range.
What does a bitwise OR do?
It sets an output bit when either corresponding input bit is one. It is often used to combine bit flags, while AND isolates bits and XOR highlights differences.

