Network mathematics · Local calculator

Bitwise Calculator

A mask lets you inspect selected positions in a header while preserving their original weights. Fixed-width bit operations also explain how a network prefix selects the upper bits of an address.

Inputs

Result

Binary result
00001000
Decimal
8
Hexadecimal
8
In this guide12 sections

Introduction

A mask lets you inspect selected positions in a header while preserving their original weights. Fixed-width bit operations also explain how a network prefix selects the upper bits of an address.

Formula and calculation

Fixed-width bitwise operations
AND: a & b; OR: a | b; XOR: a ⊕ b; NOT: a ⊕ (2^width − 1)

Operands are unsigned and limited to the selected 8, 16, 32, 64, or 128-bit word. NOT flips only the bits within that width.

width · bits
selected fixed word length
⊕ · operation
bitwise exclusive OR

Method and concepts

AND retains a one where both inputs have a one. OR sets a position when either input has a one. XOR sets the positions that differ. NOT flips every position within the selected width. Operations proceed independently in each column, with no carry between columns.

  1. Choose the unsigned width of the field in your diagram. Eight bits are enough for one octet.
  2. Enter the first value and select the operation. AND, OR and XOR need a second value in the same width. NOT uses only the first.

Binary mathematics for network engineers diagram

  1. Host octet · 10101101
  2. AND mask · 11100000
  3. Network · 10100000
  4. OR wildcard · 10111111
For 173 with a /27 boundary, masking gives the block start 160. Setting the five host bits gives its inclusive end 191.

Worked examples

Keep the upper four bits of an octet

  1. Use eight bits. The value 182 is 10110110 and the mask 240 is 11110000.
  2. Apply AND. The first four mask bits preserve 1011 and the last four clear the suffix, giving 10110000.
  3. Convert the result to decimal as 128 + 32 + 16 = 176. In an IPv4 /28 this is the start of the final-octet block containing 182.

Binary mathematics for network engineers: Check the fourth octet of 192.0.2.173/27

  1. Decompose 173 into 128 + 32 + 8 + 4 + 1, giving 10101101. The fourth mask byte for /27 is 11100000, or 224.
  2. AND the two bytes to get 10100000, or 160. Complement 11100000 within eight bits to get wildcard 00011111, or 31.
  3. OR 10100000 with 00011111 to get 10111111, or 191. Count inclusively: 191 − 160 + 1 = 32, which matches 2^5 host-field patterns.

Reference table

Bitwise Calculator reference
ABANDORXOR
00000
01011
10011
11110

Reading the result

A set bit in a mask identifies the position governed by the operation. To find what changed between two flag bytes, use XOR on their old and new values. Each one in the result marks a changed position.

Common mistakes

  • Adding two flag values with overlapping bits can produce a carry. Use OR when you intend to combine their selected positions.
  • Record the width with a NOT result. The complement of zero is 255 at eight bits and 65535 at sixteen.

Frequently asked questions

How can I clear one flag?

In an eight-bit example, a mask of 11111101 has a zero at the position worth two. AND the byte with that mask to clear that position and preserve the others.

Which mask extracts the low four bits?

Use 00001111 with AND. Applied to 10110110, it yields 00000110, the value six.

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.

Further learning and references