We do the front-end, presumably very few opportunities to contact the binary bar, those bits of the operation of what, not the bottom should be considered the problem? Yesterday saw a topic, it and binary related, but with no bit operation does not matter, with the help of JS language features, can easily solve. This is described as follows: Write a function, receive a decimal positive integer as a parameter, represent it in binary notation, and return the number of digits equal to 1. Here's an example: 1234 means that the binary is 10011010010, which has 5 1, so it returns 5. Read this description, my mind first thought is, the previous teacher teaches in class, how from Decimal to binary system (book to time side hate less ^_^). Fortunately, I have a good memory, and soon think of this positive integer to 2 to take the remainder, divided by 2, the result of 2 to take the remainder, divided by 2 ... Until the result is 0. Then, in the above procedure, a variable is used to record the number of remainder of 1, and finally return. Then there is the following approach: var countbits = function (n) {&
1. JavaScript Puzzle: Statistics binary
Introduction: We engage in the front-end, presumably very few opportunities to contact the binary bar, those bits of the operation of what, not the bottom should be considered the problem?
"Related question and answer recommendation":