Bit Manipulation Toolkit — Set, Clear, Toggle, Rotate, Reverse & Popcount
Manipulate the bits of a single value at 8, 16, 32 or 64-bit width: set, clear, toggle and test a bit by index, count set bits (popcount), count leading/trailing zeros, rotate left or right, and reverse all bits. Enter a value in decimal, hex (0x…) or binary (0b…) and read the result in binary, decimal and hex, with the changed bit highlighted.
How to Use
- Enter your value in decimal, hexadecimal (prefix 0x) or binary (prefix 0b), and pick a bit width (8, 16, 32 or 64).
- Choose an operation — set / clear / toggle / test a bit, population count, leading/trailing zero count, rotate left/right, or reverse bits.
- For bit-index or rotate operations, type the bit number (0 = least significant) or rotate amount.
- Read the result in binary (nibble-grouped, changed bit highlighted), decimal and hex — or click a bit in the binary display to toggle it directly.
Every single-bit operation in one place
Where a bitwise calculator combines two numbers, this toolkit works on the bits of one value. Enter it in decimal, hexadecimal (prefix 0x) or binary (prefix 0b), choose a width of 8, 16, 32 or 64 bits, and pick an operation. You can set, clear, toggle or test a bit by index; count the set bits (population count); count the leading or trailing zeros; rotate the value left or right; or reverse its bit order entirely. The result is reported in binary, decimal and hex at once, the changed bit is highlighted, and you can click any bit in the display to flip it directly. Everything is computed locally with JavaScript BigInt, so 64-bit values stay exact and nothing is uploaded.
Bit numbering, masking and rotation
Bits are numbered from 0 at the least significant end (the rightmost bit, worth 1) up to width − 1 at the most significant end. Internally a single-bit mask 1 << n selects bit n: set is v | (1 << n), clear is v & ~(1 << n), toggle is v ^ (1 << n), and test reads (v >> n) & 1. Counting operations look at the value masked to the chosen width: popcount tallies the 1 bits, CLZ is the width minus the position of the highest set bit, and CTZ is the index of the lowest set bit (both equal the width when the value is zero). A rotation is circular rather than a shift — bits that leave one end re-enter the other — so rotate-left by n is ((v << n) | (v >> (w − n))) & mask with n reduced modulo the width.
Quick reference
About the Bit Manipulation Toolkit — Set, Clear, Toggle, Rotate, Reverse & Popcount
Whether you are at a desk or on your phone, the Bit Manipulation Toolkit — Set, Clear, Toggle, Rotate, Reverse & Popcount makes everyday tasks easy — and it is completely free. Manipulate the bits of a single value at 8, 16, 32 or 64-bit width: set, clear, toggle and test a bit by index, count set bits (popcount), count leading/trailing zeros, rotate left or right, and reverse all bits. Enter a value in decimal, hex (0x…) or binary (0b…) and read the result in binary, decimal and hex, with the changed bit highlighted.
How it works
Type your numbers into the boxes. The answer shows up right away — you do not have to press a button. If you change a number, the answer changes too. So you can try different numbers and watch what happens, or check an answer you worked out yourself. Just make sure each box has the right kind of number in it.
Want the deeper story? The Knowledge Base explains the ideas behind the tools in more detail.
Frequently Asked Questions
How are bits numbered?
Bit 0 is the least significant bit (the rightmost, worth 1), bit 1 is worth 2, bit 2 is worth 4, and so on up to bit width−1 at the far left. Setting bit n adds 2ⁿ if it was clear; the binary display is shown most-significant-bit first, so bit 0 appears on the right.
What do set, clear, toggle and test do?
Set forces a chosen bit to 1 (value OR 2ⁿ), clear forces it to 0 (value AND NOT 2ⁿ), toggle flips it (value XOR 2ⁿ), and test reports whether it is currently 1 or 0 without changing the value. These are the four fundamental single-bit operations behind every flag and bitmask.
What are popcount, CLZ and CTZ?
Population count (popcount) is the number of 1 bits in the value. CLZ (count leading zeros) is how many 0 bits sit above the highest set bit, within the chosen width. CTZ (count trailing zeros) is how many 0 bits sit below the lowest set bit. For a value of zero, CLZ and CTZ both equal the full width. These appear as named instructions on most CPUs and are used for fast log₂, alignment and bit-scan tricks.
How does rotation differ from a shift?
A shift discards bits that fall off the end and feeds in zeros. A rotate is circular — bits that leave one end re-enter the other, so no bits are lost. Rotate left by n at width w is ((v << n) | (v >> (w−n))) masked to the width, with n taken modulo w.
Is anything sent to a server?
No. Every operation runs in your browser using JavaScript BigInt arithmetic, so 64-bit values are exact and nothing leaves your device.
How do I use the Bit Manipulation Toolkit — Set, Clear, Toggle, Rotate, Reverse & Popcount?
Just type your numbers. The answer shows up right away — there is no button to press. Change anything and it updates by itself.
Is it free? Does it work without internet?
Yes to both. It is free with no sign-up, and once the page has loaded it keeps working even with no internet.
Where does my data go?
Nowhere — every calculation runs on your own device. Nothing you enter is uploaded, logged, or stored.
Common Use Cases
Flags & bitmasks
Set, clear, toggle and test individual flag bits in permission masks, feature flags or hardware registers by index.
Embedded & firmware
Manipulate exact-width register fields, then read the result back in hex — set a control bit, rotate a field, or reverse a bus order.
Algorithms & interviews
Check popcount, leading/trailing zero counts and bit reversal — the building blocks of Hamming weight, fast log₂, FFT bit-reversal and bit tricks.
Protocols & DSP
Reverse bit order for byte-endianness or LSB-first wire formats, and rotate values for hashes and cyclic codes.
Last updated: