An interactive CLI tool for teaching binary mathematics, logic gates, and truth tables to computer science freshmen. This system provides hands-on learning with progressive difficulty levels, step-by-step explanations, and adaptive feedback.
The Binary Math Education System is designed to help students master fundamental digital logic concepts through interactive lessons and practice. Whether you're a freshman learning binary for the first time or an educator looking for teaching materials, this system provides comprehensive coverage of:
- Binary number system fundamentals: Conversion between decimal and binary, arithmetic operations, and two's complement representation
- Logic gates: Complete coverage of AND, OR, NOT, XOR, NAND, NOR, and XNOR gates with truth tables and circuit diagrams
- Truth table generation: Parse boolean expressions and generate/validate truth tables
- Interactive practice: Adaptive problem generation with immediate feedback and progressive hints
Built entirely with Python's standard library (no external dependencies), this system runs anywhere Python 3.8+ is installed.
-
Interactive Lessons with 4 modes:
- Binary Basics: Number conversion, arithmetic, two's complement
- Logic Gates: Digital electronics fundamentals with visual circuit diagrams
- Truth Tables: Boolean algebra and logic evaluation
- Practice Mode: Mixed problems with adaptive difficulty
-
Progressive Difficulty Levels:
- Beginner: Unlimited hints, step-by-step guidance
- Intermediate: Moderate assistance, 3 hints per problem
- Advanced: Minimal guidance, 1 hint per problem
-
Adaptive Learning: System adjusts difficulty based on performance metrics (accuracy, streaks, hints used)
-
Session Management:
- Automatic save/resume functionality
- Progress tracking and analytics
- Session history stored in
~/.binary_tutor/sessions/
-
Educational Features:
- Step-by-step explanations with visual aids
- 3-level progressive hint system
- Real-time answer validation
- ASCII circuit diagrams and truth tables
- Boolean algebra expressions
- Real-world analogies
-
Progress Tracking:
- Problems completed and accuracy percentage
- Current streak and total hints used
- Session duration and historical data
# Clone or download the repository
cd /path/to/binary
# No external dependencies required - uses Python standard library only!
# Python 3.8+ required
python3 --version# Start the interactive tutor CLI
python3 src/interactive_tutor.py
# Or use the demo script
python3 demo_tutor.py# Try the Python API directly
from src.binary_basics import BinaryTutor
from src.logic_gates import AND, OR, NOT
# Binary conversion
tutor = BinaryTutor(difficulty_level='beginner')
result = tutor.decimal_to_binary(42)
print(result['result']) # '00101010'
# Logic gates
gate_result = AND(True, False)
print(gate_result.result) # False
print(gate_result.explanation) # Full educational outputbinary/
├── src/ # Core modules
│ ├── binary_basics.py # Binary conversion and arithmetic
│ ├── logic_gates.py # Logic gate operations
│ ├── truth_tables.py # Truth table generation
│ ├── practice_generator.py # Problem generation engine
│ └── interactive_tutor.py # CLI interface
├── examples/ # Usage examples
│ └── logic_gates_demo.py # Logic gates demonstrations
├── demo_tutor.py # Non-interactive demo script
└── docs/ # Architecture and guides
├── QUICKSTART.md
├── ARCHITECTURE.md
└── MODULE_DOCUMENTATION.md
Binary number system tutor with difficulty-based progression
Core functionality:
decimal_to_binary(): Convert decimal to binary with division-by-2 visualizationbinary_to_decimal(): Convert binary to decimal using place value methodadd_binary(),subtract_binary(),multiply_binary(): Binary arithmetic with carry/borrow trackingto_twos_complement(),from_twos_complement(): Signed integer representationbitwise_and(),bitwise_or(),bitwise_xor(),bitwise_not(): Bitwise operationsleft_shift(),right_shift(): Bit shifting with multiplication/division effects
Educational logic gate operations with truth tables and circuit diagrams
Available gates:
NOT(a): Single-input inverterAND(a, b, ...): All inputs must be TrueOR(a, b, ...): At least one input must be TrueNAND(a, b, ...): NOT-AND (universal gate)NOR(a, b, ...): NOT-OR (universal gate)XOR(a, b, ...): Exclusive OR (different inputs)XNOR(a, b, ...): Exclusive NOR (same inputs)
Features:
- Returns
GateResultobjects with.result,.truth_table,.circuit,.explanation - Supports gate composition:
OR(AND(True, True), NOT(False)) - Flexible input types: booleans, integers (0/1), strings ('0'/'1')
Parse boolean expressions and generate/validate truth tables
Core functionality:
- Parse complex boolean expressions (e.g., "(A AND B) OR (NOT C)")
- Generate complete truth tables for any number of variables
- Validate user-provided truth tables
- Educational output with step-by-step evaluation
Adaptive problem generation with validation and hints
Features:
- Generate problems for all lesson types
- Difficulty-appropriate problem complexity
- Validate answers with flexible matching
- 3-level progressive hint system
- Performance-based difficulty adjustment
Command-line interface for interactive lessons
Architecture:
TutorOrchestrator: Main application controllerSessionManager: Save/load/resume sessionsDisplayRenderer: Colorized CLI outputInputHandler: User input validationLessonInterface: Lesson content management
from src.binary_basics import BinaryTutor
tutor = BinaryTutor(difficulty_level='beginner')
# Convert decimal 42 to binary
result = tutor.decimal_to_binary(42)
print(result['result']) # '00101010'
print(result['explanation']) # Detailed explanation
print(result['visual']) # ASCII visual aid
# Binary addition
result = tutor.add_binary('1011', '0110')
print(result['result']) # '10001'
print(result['visual']) # Shows carry propagationfrom src.logic_gates import AND, OR, NOT, XOR, compare_gates
# Basic gate operations
result = AND(True, False)
print(result.result) # False
print(result) # Full educational output
# Gate composition
result = OR(AND(True, True), NOT(False))
print(result.result) # True
# Compare multiple gates
print(compare_gates('AND', 'OR', 'XOR'))from src.truth_tables import TruthTableGenerator
generator = TruthTableGenerator()
# Generate truth table for expression
result = generator.generate_table("A AND B")
print(result['table']) # Complete truth table
print(result['visual']) # ASCII formatted table
# Validate user input
is_valid = generator.validate_table("A OR B", user_table)from src.practice_generator import PracticeGenerator
generator = PracticeGenerator(difficulty='intermediate')
# Get a practice problem
problem = generator.generate_problem('binary_basics')
print(problem['question'])
print(problem['type']) # 'binary', 'decimal', or 'text'
# Check answer
is_correct = generator.check_answer(problem['id'], user_answer)
# Get progressive hints
hint1 = generator.get_hint(problem['id'], level=1)
hint2 = generator.get_hint(problem['id'], level=2)# Launch interactive mode
python3 src/interactive_tutor.py
# Navigate menus with number keys
# Use commands during lessons:
# h - Get a hint
# n - Next question
# b - Previous question
# s - Save session
# q - Quit to menu
# ? - Show help- Python 3.8+ (uses standard library only)
- Terminal with UTF-8 support (for visual elements)
- ~50MB disk space (for code and session data)
# 1. Navigate to project directory
cd /Users/bhunt/development/claude/binary
# 2. Verify Python version
python3 --version # Should be 3.8 or higher
# 3. Test the modules
python3 src/test_modules.py
# 4. Run interactive tutor
python3 src/interactive_tutor.pyThis project uses only Python standard library:
json- Session data persistencedataclasses- Structured dataenum- Type-safe enumerationspathlib- Cross-platform file pathsitertools- Truth table generationfunctools- Memoization/caching
# Run module tests
python3 src/test_modules.py
# Run demo (non-interactive test)
python3 demo_tutor.py
# Test individual modules
python3 -c "from src.binary_basics import BinaryTutor; \
t = BinaryTutor(); \
print(t.decimal_to_binary(42)['result'])"Topics: Binary number system, base conversion, arithmetic operations
- Decimal ↔ Binary conversion (division-by-2 and place value methods)
- Binary arithmetic: addition, subtraction, multiplication
- Two's complement signed representation
- Bitwise operations: AND, OR, XOR, NOT
- Bit shifting: left (multiply) and right (divide)
Sample Problems:
- "Convert decimal 42 to binary"
- "What is 1010 + 0101 in binary?"
- "Convert -5 to 8-bit two's complement"
Topics: Digital electronics, logic gate operations, circuit design
- Basic gates: AND, OR, NOT
- Compound gates: NAND, NOR, XOR, XNOR
- Truth table generation for all gates
- Gate composition and circuit diagrams
- Boolean algebra expressions
Sample Problems:
- "What is the output of AND(1, 0)?"
- "Evaluate: OR(AND(1, 1), NOT(0))"
- "Which gate is the universal gate?"
Topics: Boolean algebra, logic evaluation, truth table construction
- Parse complex boolean expressions
- Generate complete truth tables (1-4 variables)
- Validate truth table correctness
- Understand operator precedence
- Evaluate compound expressions
Sample Problems:
- "How many rows in a truth table with 3 variables?"
- "Generate truth table for (A AND B) OR C"
- "Validate this truth table for A XOR B"
Topics: Mixed problems from all lesson types
- Adaptive difficulty based on performance
- Mixed problem types (conversion, gates, truth tables)
- Real-time performance tracking
- Streak bonuses for consecutive correct answers
Sessions are automatically saved to ~/.binary_tutor/sessions/ as JSON files:
~/.binary_tutor/sessions/
├── uuid-1234-5678-90ab.json
├── uuid-2345-6789-01bc.json
└── uuid-3456-7890-12cd.jsonFrom the main menu, select "Resume Lesson" to see active sessions:
Active Sessions:
1. Binary Basics (beginner) - 5 problems
2. Logic Gates (intermediate) - 12 problems
3. Practice Mode (intermediate) - 8 problems
View detailed statistics for any session:
- Problems completed and accuracy percentage
- Current streak (consecutive correct answers)
- Total hints used
- Session duration
- Attempt history with timestamps
Each session stores:
{
"session_id": "uuid",
"created": "ISO-8601 timestamp",
"lesson_state": {
"lesson_id": "binary_basics",
"difficulty": "beginner",
"problems_completed": 5,
"correct_answers": 4,
"accuracy": 80.0,
"current_streak": 2,
"hints_used": 3,
"attempts_history": [...]
}
}- Create lesson content in appropriate module (
binary_basics.py,logic_gates.py, etc.) - Add problem generation logic to
practice_generator.py - Update
LessonInterfaceininteractive_tutor.py - Add lesson to menu in
TutorOrchestrator
- Add new problem type to
PracticeGenerator.generate_problem() - Implement answer validation in
PracticeGenerator.check_answer() - Create progressive hints in
PracticeGenerator.get_hint() - Update input validation in
InputHandler.get_answer()
- Use type hints for all function parameters and returns
- Write docstrings with examples for public methods
- Keep functions focused and single-purpose
- Use dataclasses for structured data
- Follow PEP 8 style guidelines
- Add educational value - explain the "why" not just the "what"
For detailed architecture documentation, see:
/Users/bhunt/development/claude/binary/ARCHITECTURE.md- Complete system architecture/Users/bhunt/development/claude/binary/QUICKSTART.md- Getting started guide/Users/bhunt/development/claude/binary/src/MODULE_DOCUMENTATION.md- API reference
- Educational First: Every operation includes explanations, not just answers
- Progressive Complexity: Start simple, add complexity as students improve
- Visual Learning: ASCII diagrams and formatted output for visual learners
- Immediate Feedback: Real-time validation and hints
- Persistent Progress: Sessions save automatically for continuous learning
Author: bhunt Role: Network Engineer & Developer Purpose: Educational tool for computer science freshmen
License: This is an educational project. Feel free to use, modify, and distribute for learning purposes.
QUICKSTART.md- 5-minute getting started guideQUICK_REFERENCE.md- Cheat sheet for common operationsEXAMPLE_SCENARIOS.md- Real-world usage examplesIMPLEMENTATION_GUIDE.md- Developer guide for contributors
ARCHITECTURE_SUMMARY.md- High-level system overviewINTERACTIVE_TUTOR_ARCHITECTURE.md- CLI design patternsLOGIC_GATES_ARCHITECTURE.md- Logic gates implementationSYSTEM_DIAGRAMS.md- Visual architecture diagrams
For questions, issues, or contributions:
- Check existing documentation in
/docs/ - Review example usage in
/examples/ - Run the demo script:
python3 demo_tutor.py - Contact: bhunt (Network Engineer & Developer)
Happy Learning! Master binary mathematics, logic gates, and digital electronics with interactive, adaptive lessons designed for freshman computer science students.