100DaysOfCode Day 12: Binary Conversion with Python

Day 12 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to convert a decimal number into its binary representation without using built-in functions like bin(). The goal was to understand how number base conversion works internally. What the program does: • Takes a decimal number as input • Uses division and modulo operations • Builds the binary representation manually • Returns the final binary number as a string How the logic works: An empty string binary is initialized to store the result A while loop runs as long as the number is greater than 0 The remainder when dividing by 2 (n % 2) is calculated The remainder is added to the front of the binary string The number is reduced using integer division (n // 2) The loop continues until the number becomes 0 The final binary string is returned Example: Input - 34 Output - Binary representation of 34 is: 100010 Key learnings from Day 12: – Understanding number system conversion – Using modulo and integer division effectively – Building logic step-by-step without built-in shortcuts – Strengthening fundamental programming concepts #100DaysOfCode #Day12 #Python #PythonProgramming #NumberSystems #BinaryConversion #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney

  • text

To view or add a comment, sign in

Explore content categories