Day 2 of DSA Daily: Exploring Binary Numbers and Simple Problems

Another day of my Data Structures and Algorithms (DSA) series. Today, I continued my learning by completing the sixth video in Babar's DSA Playlist. You can find the video here: Babar's DSA Playlist - Video 6.

The video covered the Binary and Decimal Number Systems. Although I had a theoretical understanding, the video helped in showing me how to implement these concepts in code.

I started by working on a simple program that converts a decimal number to a binary number. Here's a basic idea of what the code looked like:

//convert decimal to binary
#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int i=0;
    int ans = 0;

    while(n!=0){
        int bit = n&1;
        ans = (bit * pow(10,i)+ans);
        n=n>>1;
        i++;
    }
    cout<<ans<<endl;
}

Following that, I solved a question on LeetCode where I had to reverse an integer. Here's the link to the problem: Reverse Integer. I managed to solve it independently.

That sums up my progress for today. Tomorrow, I plan to solve more problems on LeetCode and continue learning new concepts.

Best regards,
Jay Chavan.