# COME ON CODE ON

A blog about programming and more programming.

## Builtin Functions

There are some useful bulitin function in gcc. Here are some of them :

Built-in Function: int __builtin_ffs (unsigned int x)

Returns one plus the index of the least significant 1-bit of x, or if x is zero, returns zero.

Built-in Function: int __builtin_clz (unsigned int x)

Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.

Built-in Function: int __builtin_ctz (unsigned int x)

Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.

Built-in Function: int __builtin_popcount (unsigned int x)

Returns the number of 1-bits in x.

Built-in Function: int __builtin_parity (unsigned int x)

Returns the parity of x, i.e. the number of 1-bits in x modulo 2.

Try them out yourself. Here’s a sample program.

```int main()
{
int x=30;
printf("Index of least significant bit:%d\n",
__builtin_ffs(x)-1);
__builtin_clz(x));
printf("Index of highest set bit:%d\n",
31-__builtin_clz(x));
printf("Number of trailing zeroes :%d\n",
__builtin_ctz(x));
printf("Number of 1-bits:%d\n",
__builtin_popcount(x));
printf("Parity:%d\n",__builtin_parity(x));

printf("File Name:%s\n",__FILE__);
printf("DATE:%s\n",__DATE__);
printf("TIME:%s\n",__TIME__);
}```

Also many times in graph algorithms we require +ve INFINITY and -ve INFINITY in our programs. There you can use :

int main()
{
printf(“+ve INFINTY: %d\n”,INT_MAX);
printf(“+ve INFINTY: %d\n”,(1<<31)-1);     printf("-ve INFINTY: %d\n",INT_MIN);     printf("-ve INFINTY: %d\n",1<<31); }[/sourcecode] PLAY WITH BITS!!!If you know others do share. -fR0D