Hey, guys, what's up?
So we are solving another interesting problem today.
So the problem is given a number and given a number.
And we have to today.
We have to.
How many times?
How many times when I'll be at.
And it's binary representation.
So we have to tell how I mean, at times when I appear in the binary representation of dead.
No.
For example, the given number is five.
So the binary presentation of five is zero zero zero one zero one.
So my output should be to.
Let's say four and equals to seven and four.
And it was 15.
So here my output is when, when, when.
So I have my own binary presentation is one when one.
So my output will be three and four fifteen.
My binary presentation will be this and the output will be four because there are four ones.
So given a number and we have to tell how many times will not be in its binary representation.
So actually, one is also going to set a bit.
So you can also say this problem is calculated.
Number of sentiment's in ENIM but.
In binary representation of a number in binary is imitation offer, no.
So sad, but it is nothing.
It is just when one is called said but.
OK, so this problem can also be in this session, also hear the number of securites in Bindoon presentation
of a number.
So any idea how we can solve it?
So we have to use bitwise operators to solve this problem.
So suppose and it was seven.
So what is that binary presentation?
Seven zero zero zero and one one in one.
So what do I really do?
First of all, I will take.
No.
And when?
OK.
Take no end one.
So binary presentation of one is one and zero zero zero zero zero.
So we have to take.
And so since it is zero zero zero zero zero.
So output will be zero zero zero.
And two, because if you remember the end on one and one will give me one.
Otherwise, all of their cases will give me zero.
So if there is one zero, all parties zero.
Now let us focus.
What will you output here?
So output is one and one is one.
Now convert this number into decimal.
So when.
OK, so.
And and one is giving me one.
Now, I will update the number.
What I will do, I will.
I will shift the number towards.
Right.
So no liquids, no light shift one.
So my number become zero zero zero zero one and one.
So this is my updated number again.
I will take no and when.
So here I am having one less dollar.
Zero.
We have to take.
And so zero zero zero zero zero.
So one and one is one.
So I am getting one again.
Now I will update the number again number as it goes to a number.
Let's shift one.
So number equals number.
Right.
Shift one.
So zero zero zero zero zero.
And one.
Now we have to take.
Number and one.
So zero zero zero zero zero.
And when we have to take.
And so this will be zero zero zero zero zero.
So one and one is one.
Again, remember when.
Now we again shift the number.
So number equals number.
Right.
Shift one.
So it will become zero zero zero zero zero and zero.
So number becomes zero.
Stop.
Number becomes zero.
Stop.
And now we will see how they will calculate our output.
So here you can see one, one and one.
Adam, my output is three.
So in binary presentation of seven, you can see one appeared two times.
OK, so this is the logic.
Let's try our logic for one more kiss.
Suppose.
And it was five.
So it is the binding presentation of five zero zero one zero one dick and with one number equals.
Sorry.
No.
And one.
So this is the binding presentation of one zero zero zero zero.
We have to take.
And so since this is zero zero zero zero.
This is zero zero.
Because only one end of one is one arrest or a lot of zero.
Now take one.
And one is one.
So remember one here.
Now I will update my number.
Number equals number.
Right.
Shift one.
So shift the number towards.
Right.
So zero zero zero one and zero.
And now number and one.
So this is one.
And we have to take.
And so since this is zero.
Since this is zero.
Now if and of one zero will also be zero.
Because only one end of one is one.
Otherwise all at zero.
So this number is giving me zero.
Again.
Right.
Check the number by one.
So why number becomes zero zero zero zero.
And one.
And number.
And one.
So zero zero zero zero one.
We have Rubick and one zero zero zero zero.
So it is giving me one.
Now, if we will shift one more time.
Number towards right.
It will become zero zero zero zero zero, which is zero.
So it will become zero.
Hence I will stop.
Now add all these one plus zero plus one gives me two.
You can see here.
Binary presentation in binary presentation of five.
Arbitrary two.
And I'm getting to.
Now, one last example, number is one.
OK, so binary visitation of one is zero zero zero one.
Let's one.
And we have to take a number and one.
So zero zero zero one big.
And so since this is zero one zero assistances, zero zero since this is zero zero.
And here I will get one convert the number and decimal I may get one number equals number shift one.
So if you will share the number two right, it will become zero.
I will stop.
And this is my answer.
OK.
So what I will do, I will take a variable and count it equals zero initially my variable count will
contain zero.
What is count?
Count is how many times when appear.
Guys are going to a table will store how many times when appear in the binary representation of a number.
So end count equals zero.
How many times I have to run the loop while Lember is bigger than zero.
And what I have to do, I have to take and off.
Number.
OK, so count equals count plus number and one.
OK, so this value will either be one or this value will either be zero.
There are no other possibilities.
OK.
Either it will be zero.
Either it will be one.
And then we will update our number.
Number equals number.
Right.
Shift one.
Finally we will see out.
Gonged.
OK.
So I am saying that there are only two possibilities.
Either this number will be zero or the number that we will get is when.
If this number is at zero, it will not have any effect on account variable.
It will not have any effect on my variable count, because if you add a zero to a number, it will remain
the same.
But if it is one, that means card will be implemented by one.
Now why?
I am saying that the number will either be zero or the number will either be one because I'm taking
and with one.
OK.
So here binary presentation of one is one and rest or allows you to suppose this is binary number.
And if you take and it doesn't matter whether X is zero or one, these four bits are going to be zero
only.
This bit if they're deciding.
OK.
So if X is one, if X is one, I really get one here.
If X is zero, I will get zero here.
And if you will convert, if you will convert this number to decimal, it is one.
If you convert this number two decimal, it is zero.
So there are only two possibilities that I will get.
One, that I will get zero if I am getting zero.
There is no effect on Gonta variable.
If I'm getting one, that means that here I was having one and one means set with and we have to calculate
the set with only.
So it will be added to my variable count.
OK, so that is the logic.
So what is the logic?
Logic is very simple, just shifted the number towards right and Dick and with the last digit back end
of the last digit.
If last digit is one, I will get one and count will be incremented.
If the last digit is zero.
If last digit is zero, I will get zero and zero and one zero and one will be zero.
So card will not be effected.
So I know this thing is a difficult to understand, but what you should do is, again, it is it just
comes with practice only.
So what you should do is use pen and paper and write down the steps which are involved in solving the
problem.
So let us name this file as.
Nemeroff.
No off when.
Nazi CPB.
So what do we have to do?
I will take and as input.
And I am taking a variable count which will tell me how many times when I appeared in the binary presentation.
So initially I can't really be zero.
So why in my number is greater than zero.
What I will do.
Clowned plus equals to No.
And one.
OK, so this is a tricky part.
But why this tricky?
Because you have not practiced any problem of this kind.
So you may be facing very difficult days, I know.
And that is obvious.
That is very natural because you have notes, all these kinds of problem.
So how you can come up with the solution.
Obviously, you can't come up.
OK, so once we have solved this type of question, then you will be able to understand it, how we
can solve it.
OK.
So no end you that this will be zero or one.
And we have to upgrade the number.
So number equals number.
Right.
Shift one.
And then finally, we will see out count.
So this is all that we have to do.
So let's not vote on.
So for any good faith, my approach would be to correct.
Four.
And it was seven, my output should be three, correct?
For any clues, let's say, when Marbut should be when correct?
Shalako is correct.
So when last time.
I know it is very difficult to understand how I approached this problem.
How do I know that it will work?
And why it is difficult for you, because this is your first time, your first time encountering these
types of problem.
So it is very difficult to understand.
I know.
So what do you do is you will write discord on pen and paper.
Take some values, often drive in your code.
The steps that are involved in each step right there look for the value of count.
What is an end of one road shift?
And by one and all these steps.
OK.
So if you have any problem, feel free to ask.
OK.
So this is it for this video.
Thank you.