Results for “bit”
Small, practical examples. Search by task or narrow things down below.
Store and inspect a fixed set of bits
C++: bitset offers named operations and a readable binary representation.
C++✓ Tested
Toggle a bit with an XOR mask
Arduino / C: XOR flips selected bits and leaves all other bits unchanged.
Arduino / C✓ Tested
Calculate a fixed-window moving average
C: For this small window, sum each complete group and skip incomplete prefixes.
C✓ Tested
Calculate a least common multiple using a GCD
C: Divide before multiplying to reduce the risk of intermediate overflow.
C✓ Tested
Calculate a small factorial iteratively
C: Multiply a bounded sequence using an unsigned accumulator.
C✓ Tested
Calculate an average without integer division truncation
C: Accumulate into double and divide by the nonzero number of readings.
C✓ Tested
Calculate the greatest common divisor
C: Euclid’s algorithm repeatedly replaces a pair with the divisor and remainder.
C✓ Tested
Compute a simple XOR checksum
C: XOR all payload bytes into one byte to demonstrate a basic error-detection field.
C✓ Tested
Generate a bounded Fibonacci sequence
C: Keep only the two previous values instead of using exponential recursive calls.
C✓ Tested
Sum the decimal digits of an unsigned integer
C: Repeated division and remainder extract digits without converting to text.
C✓ Tested
Test whether an unsigned value is a power of two
C: A nonzero power of two has exactly one set bit.
C✓ Tested
Average a fixed set of readings
Accumulate sample values without overflowing a 16-bit total.
array✓ Tested