Builtin functions of GCC compiler
What is GCC compiler?
GCC stands for GNU Compiler Collection, which is the collection of compilers which is generally used in C or C++ programs to convert the code into assembly language.
We have a lot of inbuilt functions provided by the GCC, which are as follows:
This function is used to return the number of set bits or number of 1s in a decimal number. It takes one argument as a decimal number and returns the number of 1s presented in it.
As we know, we can represent any decimal number in binary format, representing a series of 1s and 0s.
For example: int a = 12;
We can represent 12 as 1100 in the binary format, so the number of 1's in the given integer is 2.
Note: We can use this function for long and long long data types, but the function name will be slightly changed.
For long datatype: __builtin_popcountl()
For long long data type: __builtin_popcountll()
This function is used to determine the parity of a number. Parity means the number of set bits is even or odd. So if the number of set bits is odd, then it will return true or return one. Else, it will return false or return 0.
In the above example, we can represent 12 in binary format as 1100, so it has 2 number of set bits, so for this example, the above function will give output as 0.
We can represent 13 in binary format as 1101, so it has 3 number of set bits, which is odd, and this function will return 1.
Note: We can use this function for long and long long data types: