diff --git a/frontend/src/components/visualizations-new/data-structures/bit-manipulation-view.tsx b/frontend/src/components/visualizations-new/data-structures/bit-manipulation-view.tsx new file mode 100644 index 0000000..5dfb261 --- /dev/null +++ b/frontend/src/components/visualizations-new/data-structures/bit-manipulation-view.tsx @@ -0,0 +1,154 @@ +'use client'; + +import { motion } from 'framer-motion'; +import { cn } from '@/lib/utils'; +import type { BitManipulationState } from '@/lib/visualizations/types'; +import { BitDisplay } from '../primitives/bit-display'; + +interface BitManipulationViewProps { + state: BitManipulationState; + bitWidth?: number; + className?: string; +} + +const OPERATION_SYMBOLS = { + XOR: '⊕', + AND: '&', + OR: '|', + NOT: '~', +} as const; + +export function BitManipulationView({ + state, + bitWidth = 4, + className, +}: BitManipulationViewProps) { + const hasOperation = state.operation && state.operands.length >= 2; + const hasResult = state.result; + + return ( +
+ {/* Label */} + {state.label && ( + + {state.label} + + )} + + {/* Operation layout */} +
+ {/* Operands */} + {state.operands.map((operand, index) => ( + + {/* Show operation symbol before second operand */} + {index === 1 && hasOperation && ( + + {OPERATION_SYMBOLS[state.operation!]} + + )} + {index === 0 && hasOperation && ( + /* Spacer for alignment */ + )} + + + ))} + + {/* Divider line and result */} + {hasResult && ( + <> + + + + = + + + + + )} +
+
+ ); +} + +interface BitXORSequenceProps { + states: BitManipulationState[]; + bitWidth?: number; + className?: string; +} + +export function BitXORSequence({ + states, + bitWidth = 4, + className, +}: BitXORSequenceProps) { + return ( +
+ {states.map((state) => ( + + ))} +
+ ); +} + +interface BitArrayWithBinaryProps { + values: Array<{ + value: number; + bits: string; + state: 'normal' | 'highlighted' | 'comparing' | 'result' | 'cancelled'; + }>; + bitWidth?: number; + label?: string; + className?: string; +} + +export function BitArrayWithBinary({ + values, + bitWidth = 4, + label, + className, +}: BitArrayWithBinaryProps) { + return ( +
+ {label && ( + + {label} + + )} +
+ {values.map((item, index) => ( + + ))} +
+
+ ); +}