Binary to Octal Conversion Challenge Completed

Day 26 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Convert Binary to Octal We were given a binary number. Task was to convert it into octal. Octal uses base 8. And 1 octal digit = 3 binary bits. So the key idea is simple. Group the binary digits in sets of three. Example: Binary → 101110 Group into 3 bits: 101 | 110 Convert each group: 101 → 5 110 → 6 Octal = 56 💻 Approach 🔹️Take the binary string. 🔹️Check its length. 🔹️If length is not multiple of 3, add leading zeros. 🔹️Traverse the string in groups of 3 bits. 🔹️Convert each group using positional values (4, 2, 1). 🔹️Append the result to the final answer. Simple grouping logic. 📊 Complexity Analysis Time Complexity: O(n) Each bit is processed once. Space Complexity: O(n) Output string depends on input size. 📚 What I learned today: ▫️Binary can be converted easily using bit grouping. ▫️3 binary bits directly map to 1 octal digit. ▫️Padding zeros does not change the value. ▫️Understanding number system relationships simplifies conversions. Day 26 completed. Number system concepts getting clearer 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic

To view or add a comment, sign in

Explore content categories