Gautam's Blog

The technical blog of Gautam!

Browsing Posts in C

I have been playing around with FUSE. Hopefully, I get some time to work on it! I am planning to work on a provenance framework.

MaxMind offers GeoIP database. It allows you to plot the location of the IP addresses using country information or more precise information such as the latitude and longitude of the location of the IP address.

#include <stdio.h>
int main()
{
int i, j, k, l=0;
while(1)
{
printf(“Number: “);
scanf(“%d”,&i);
l = 0;
for(j=0;j<16;j++)
{
k=i>>j;
if (k&1)
l++;
}
if(l==1)
printf(“Power of 2: %d\n”, l);
else
printf(“Not a power of 2: %d\n”,l);
}
return 1;
}

#include <stdio.h>
int main()
{
int i, j, k, l=0;
while(1)
{
printf(“Number: “);
scanf(“%d”,&i);
l = 0;
for(j=0;j<16;j++)
{
k=i>>j;
if (k&1)
l++;
}
if(l==1)
printf(“Power of 2: %d\n”, l);
else
printf(“Not a power of 2: %d\n”,l);
}
return 1;
}

Big endian is where Most Significant Byte is handled first. Little endian is where Least Significant Byte is handled first.

To determine if a machine is Big endian or little endian, declare an integer (which has its MSB=0) and create a character pointer to the location and print the character value at the address. If the value is same as the
integer, it is Little endian otherwise it is Big endian.

#include <studio.h>

int main()
{
int i =1;
char * pc = (char *)&i;
if (*pc == 1)
printf(“Little endian.\n”);
else
printf(“Big endian.\n”);
}

#include <stdio.h>
int main()
{
int i=9, j, k, l=0;
for(j=0;j<16;j++)
{
k=i>>j;
if (k&1)
l++;
}
if(l==1)
printf(“Power of 2: %d\n”, l);
else

printf(“Not a power of 2: %d\n”,l);

return 1;
}

Some user-level socket code can be found here.

Working with Socket can be found here.

The code listed here by Ankan, works for me!

Following is a great example for an ftp client in kernel. However, sock_alloc symbol has been removed in 2.6.10. Watch out for it.

Gcc provides an option to increase the performance of your code. The optimization will increase the size of your code. I needed faster run time with the code that maintained 3 double linked lists. I had optimized the code by removing some obvious steps. When i used the options mentioned here, the speed increased quite a bit. The size of the executable was just 20 bytes more. I am willing to trade speed for that small increase.

One of my friends had suggested compiling the kernel with that option. He said, the system was faster. Hmm, gotta try that soon.

Powered by WordPress Web Design by SRS Solutions © 2012 Gautam's Blog Design by SRS Solutions