Clear Bit (Bit Clear)

Reset a specific bit in a binary number to zero

Bit Clear Calculator

Bit Operation: Clear

This function clears (sets to 0) a specific bit in a binary number. The numbering starts with the rightmost bit at position 0.

Example: FF (hex) = 255 (dec) = 11111111 (binary)
Position 0: rightmost bit | Position 1: second bit | Position 2: third bit, etc.
Results after Bit-Clear Operation
Binary:
Octal:
Decimal:
Hexadecimal:

Bit-Clear Visualization

Example: FF (hex) → Clear Bit 2
Original: 1 1 1 1 1 1 1 1
Position: 7 6 5 4 3 2 1 0
After Clear Bit 2: 1 1 1 1 1 0 1 1
FB (hex) = 251 (dec)
Bit Clear Operation

Target Bit = 0

Other bits remain unchanged

Logical AND operation with mask
Important Properties
  • Bit position starts at 0 (right)
  • Only the specified bit is set to 0
  • Already set 0-bits remain unchanged
  • Operation is idempotent (multiple executions = same effect)


Mathematical Foundations of Bit-Clear Operation

The Bit-Clear operation uses a logical AND operation with a special mask:

Mask Creation
\[\text{Mask} = \sim(1 \ll n)\]

n = bit position, ~ = bitwise negation, << = left shift

Bit-Clear Operation
\[\text{Result} = \text{Original} \And \text{Mask}\]

Logical AND operation with the generated mask

Bit-Clear Formulas and Examples

General Bit-Clear Formula
\[\text{clear\_bit}(x, n) = x \And \sim(1 \ll n)\]

Where x is the original number and n is the bit position

Step-by-Step Example: Clear Bit 2 in FF (hex)

1. Original: 11111111₂ (FF hex = 255 dec)

2. Bit Position: n = 2

3. Create Mask: 1 << 2 = 00000100₂

4. Negate Mask: ~00000100₂ = 11111011₂

5. AND Operation: 11111111₂ & 11111011₂ = 11111011₂

6. Result: FB hex = 251 dec

More Examples
Clear Bit 0 in 15 (dec):
Original: 1111₂ (15)
Mask: ~0001₂ = 1110₂
Result: 1111₂ & 1110₂ = 1110₂ (14)
Clear Bit 3 in 255 (dec):
Original: 11111111₂ (255)
Mask: ~00001000₂ = 11110111₂
Result: 11110111₂ (247)
Bit Position Mapping
8-Bit Example:
Bit Position: 7 6 5 4 3 2 1 0
Bit Value: 128 64 32 16 8 4 2 1
Binary: 1 1 1 1 1 1 1 1

Position 0 = least significant bit (LSB), Position 7 = most significant bit (MSB)

Bit-Clear Reference

Standard Example
Original: FF (hex) Bit 2 clear: FB (hex) Difference: -4 (dec)
Bit Values (Powers of 2)

Bit 0: 2⁰ = 1

Bit 1: 2¹ = 2

Bit 2: 2² = 4

Bit 3: 2³ = 8

Bit 4: 2⁴ = 16

Bit 5: 2⁵ = 32

Bit 6: 2⁶ = 64

Bit 7: 2⁷ = 128

Logical Operators

&: bitwise AND

~: bitwise negation (NOT)

<<: left shift

>>: right shift

Common Operations

Set Bit: x | (1 << n)

Clear Bit: x & ~(1 << n)

Toggle Bit: x ^ (1 << n)

Check Bit: (x >> n) & 1

Bit Manipulation - Detailed Description

Bit Clear Operation

The bit-clear operation is a fundamental bitwise operation that sets a specific bit in a binary number to 0, while leaving all other bits unchanged. This operation is particularly important in systems programming and embedded systems.

Properties:
• Target bit is always set to 0
• Other bits remain unchanged
• Operation is idempotent
• Based on logical AND operation

Mask Technique

The mask technique is the heart of the bit-clear operation. A mask is created that contains a 0 at the desired position and 1s at all other positions. This mask is then AND-combined with the original number.

Mask Creation

1. Create bit pattern: 1 << n
2. Negate the pattern: ~(1 << n)
3. AND operation: original & mask

Practical Applications

Bit-clear operations are used in many areas, from hardware control to data processing. They enable precise control over individual bits without affecting other data areas.

Application Areas:
• Hardware register control
• Status flag management
• Bit masks for permissions
• Data filtering and cleaning

Bit Position System

The bit position system starts at 0 for the least significant bit (LSB) and increases to the left. Position n corresponds to the decimal value 2^n.

Important Notes
  • Bit numbering starts at 0 (not 1)
  • Position 0 = rightmost bit (least significant)
  • Already set 0-bits remain unchanged
  • Operation works with all number systems

Practical Bit-Clear Examples

Hardware Register

Scenario: Turn off LED

Register: 10110111₂

Clear Bit 3: 10100111₂

Effect: LED at position 3 off

Status Flags

Scenario: Clear error flag

Status: 11111111₂

Clear Bit 7: 01111111₂

Effect: Error flag cleared

Permissions

Scenario: Revoke write permission

Rights: 111₂ (rwx)

Clear Bit 1: 101₂ (r-x)

Effect: Read and execute only

Programming Tips
  • Use constants: #define BIT2 (1<<2)
  • Define macros: #define CLEAR_BIT(x,n) ((x) & ~(1<<(n)))
  • Use bit fields: for structured data
  • Debugging: Binary output for control
  • Portability: Consider bit size (8/16/32/64 bit)
  • Performance: Bit operations are very fast

Is this page helpful?            
Thank you for your feedback!

Sorry about that

How can we improve it?


IT Functions

Decimal, Hex, Bin, Octal conversionShift bits left or rightSet a bitClear a bitBitwise ANDBitwise ORBitwise exclusive OR

Special functions

AiryDerivative AiryBessel-IBessel-IeBessel-JBessel-JeBessel-KBessel-KeBessel-YBessel-YeSpherical-Bessel-J Spherical-Bessel-YHankelBetaIncomplete BetaIncomplete Inverse BetaBinomial CoefficientBinomial Coefficient LogarithmErfErfcErfiErfciFibonacciFibonacci TabelleGammaInverse GammaLog GammaDigammaTrigammaLogitSigmoidDerivative SigmoidSoftsignDerivative SoftsignSoftmaxReLUSoftplusSwishStruveStruve tableModified StruveModified Struve tableRiemann Zeta

Hyperbolic functions

ACoshACothACschASechASinhATanhCoshCothCschSechSinhTanh

Trigonometrische Funktionen

ACosACotACscASecASinATanCosCotCscSecSinSincTanDegree to RadianRadian to Degree