Update main.cpp

Overall changes:
      - Made the code more modular overall and generic to do x bit to y bit mapping.