We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I'm having trouble understanding why this work. For example, let's use the number 65. It's greater than 0 so the while loop starts.
rem = 1
n = 32
And then the if statement executes. And because S goes up from 0 to 1, t becomes 1.
But the second time around 32 is divided evenly and REM = 0. Doesn't this mean that the else statement executes and s = 0. So every time there is a 1 it gets stored in T. If there are two 1's then 2 increments by 2.....
Is that correct?
so 101101 Would produce 4?
Forgive me if I'm dense.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
I'm having trouble understanding why this work. For example, let's use the number 65. It's greater than 0 so the while loop starts.
rem = 1 n = 32
And then the if statement executes. And because S goes up from 0 to 1, t becomes 1.
But the second time around 32 is divided evenly and REM = 0. Doesn't this mean that the else statement executes and s = 0. So every time there is a 1 it gets stored in T. If there are two 1's then 2 increments by 2.....
Is that correct?
so 101101 Would produce 4?
Forgive me if I'm dense.