Overview

Bit string flicking involves manipulating strings of binary digits (0s and 1s) using various operators. This concept is fundamental in systems programming, assembly language, code optimization, and hardware design.

Importance in Modern Programming

Key Concepts

Bitwise Operators (Changes a single bit)

NOT (~)

Flips the value of a bit (0→1, 1→0)

xNOT x
01
10

Example: ~100 = 011

AND (&)

Both input bits must be 1 for output to be 1

xyx AND y
000
010
100
111

Example: 110 & 011 = 010

OR (|)

Output is 1 if either input bit is 1

xyx OR y
000
011
101
111

Example: 110 | 011 = 111

XOR (⊕)

Output is 1 if input bits are different values

xyx XOR y
000
011
101
110

Example: 110 ⊕ 011 = 101

Shift Operators (Changes a bit string)

Order of Precedence

  1. NOT (~)
  2. SHIFT and CIRC operations
  3. AND (&)
  4. XOR (⊕)
  5. OR (|)

* Equal precedence operators are evaluated left to right

Examples

Shift and Circulate Examples

LSHIFT

Example: LSHIFT-2 01101

  1. Original: 01101
  2. Shift left 2 spaces: 101__
  3. Fill with zeros: 10100

Result: 10100

RSHIFT

Example: RSHIFT-3 01101

  1. Original: 01101
  2. Shift right 3 spaces: ___01
  3. Fill with zeros: 00001

Result: 00001

LCIRC

Example: LCIRC-3 01101

  1. Original: 01101
  2. Take first 3 bits: 011|01
  3. Move to end: 01|011

Result: 01011

RCIRC

Example: RCIRC-1 01101

  1. Original: 01101
  2. Take last bit: 0110|1
  3. Move to front: 1|0110

Result: 10110

Combining Operators

Example: Evaluate NOT 10110 AND LCIRC-2 01101 OR 00011

Follow the order of precedence: NOT first, then shifts, then AND, then OR.

  1. NOT 10110 = 01001
  2. LCIRC-2 01101 = 10101 (move the first two bits, 01, to the end)
  3. AND the two results: 01001 AND 10101 = 00001
  4. OR with 00011: 00001 OR 00011 = 00011

Result: 00011

Practice Problems

Problem 1 Junior

Evaluate the following expression:

(10111 XOR NOT 10100 AND 11101)

Note: Keep in mind the order of operations

Problem 2 Intermediate

Simplify the following expression:

(LCIRC-2 (NOT 10111) OR (RSHIFT-2 (LCIRC-1 10010 AND NOT 00010)))

Problem 3 Intermediate

Evaluate the following:

D2316 XOR 9F216

Both numbers are 12-bit hexadecimal values. Express your answer as a 3-digit hexadecimal string.

Tip: To convert hexadecimal to binary, you can convert each hex digit to a 4-digit binary number and then combine them.

Problem 4 Senior

Solve for X (5-bits) in the following equation:

01101 XOR (RCIRC-2 X) = 01111

Problem 5 Senior

Evaluate the following expression:

(NOT 10101 OR LCIRC-2 01100 OR LCIRC-1 00111 AND RSHIFT-2 10010)