21 Days of Code: Day 1 - Bit Manipulation Fundamentals

🚀 21 Days of Code — Day 1/21 Restarting my 21 Days of Code journey with a problem that helped me revisit binary representation and bit manipulation fundamentals. ⸻ 🧩 Problem Statement A positive integer N is given. Steps to solve: 1. Convert the decimal number to its binary representation 2. Toggle all bits starting from the most significant bit (including MSB) 3. Convert the toggled binary back to decimal and print the result 📌 Example: Input: 8 Binary: 1000 After toggling: 0111 Output: 7 ⸻ 💡 Approach I Used • Converted the decimal number to binary using bitwise AND (&) and right shift (>>) • Stored the binary representation manually • Toggled each bit by checking '0' and '1' • Recalculated the decimal value of the toggled binary 🔍 Key Takeaway Working at the bit level strengthens logical thinking and makes complex-looking problems much easier to break down. 📌 Day 1/21 complete Consistency over perfection — showing up every day 💪 #21DaysOfCode #Java #BitManipulation #DigitalLogic #DSA #LearningInPublic #ProblemSolving #DrGVishwanathanChallenge

  • graphical user interface, text, application
Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories