Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this function do?

Tags:

I am reading a program which contains the following function, which is

int f(int n) {     int c;     for (c=0;n!=0;++c)          n=n&(n-1);     return c; } 

I don't quite understand what does this function intend to do?

like image 826
user297850 Avatar asked Jul 16 '10 14:07

user297850


People also ask

What does is an function do?

Functions are "self contained" modules of code that accomplish a specific task. Functions usually "take in" data, process it, and "return" a result. Once a function is written, it can be used over and over and over again. Functions can be "called" from the inside of other functions.

What does this function do in JavaScript?

“This” keyword refers to an object that is executing the current piece of code. It references the object that is executing the current function. If the function being referenced is a regular function, “this” references the global object.

What is $() in JavaScript?

The $() function The dollar function, $(), can be used as shorthand for the getElementById function. To refer to an element in the Document Object Model (DOM) of an HTML page, the usual function identifying an element is: document. getElementById("id_of_element").

What does $( function () do in jQuery?

$(document). ready(function() { ... }); What it's designed to do (amongst other things) is ensure that your function is called once all the DOM elements of the page are ready to be used.


1 Answers

It counts number of 1's in binary representation of n

like image 126
Vladimir Avatar answered Sep 23 '22 01:09

Vladimir