Some interesting read on Bit Twiddling: setting and resetting(clearing) bit

a | b…. a & c…….a^b…..~a*(a^b)…..

If above criptic notations make some sense for you and you enjoyed reading above then here is some resource for you. I was actually searching way to set or reset a bit on a number. Finally i got some solution to share:

Setting a bit:
number = number | (1 << n); //(it will set (n+1) th bit)

num1 = 32;//100000
n = 2;
num2 = num1 | (1<<n);//num2=36 (100100)…it is setting 3rd bit

Resetting(Clearing) a bit:
number = number & ~(1<<n); //it will clear (n+1)th bit.

num1 = 34; //100010
n = 1;
num2 = num1 & ~(1<<n); //num2=32(100000)…it is clearing 2nd bit

using above we can write function to set and reset bit:

/*set the bit at bitPos*/
int setBit(int num,int bitPos)
  return num | (1<<(bitPos-1));

and to clear:

/*reset(clear) the bit at bitPos*/
int resetBit(int num, int bitPos)
  return num & ~(1<<(bitPos-1));

Here I have found some good resource on bit twiddling:

Bit Twiddling Hacks

Some thing more advance:

Advanced bit manipulation-fu


1. Stack Overflow

introduction to interop: some good article from net

I was looking for some good tutorial on net for com interop, i got following nice articles:

Published in: on January 20, 2010 at 12:30 pm  Leave a Comment  
Tags: , , , ,

finding information about an IP address on the web

Today i need to find information about an ip address, i got from internet. This thing can also happen when you get any spam or something from an ip and you need information about that ip. ARIN WHOIS Database Search helped me to get more information about ip. following is the URL of it:

For example if you want to know whom ip belongs, you can type this ip in left text box on the site and on clicking submit query button you will have complete information.

C# tips & tricks: Do you want to rethrow exception ?

Many times during development we really don’t want to handle exception every where, rather we like to throw it again. But what is the best way to do it:

catch(Exception ex)


catch(Exception ex)
throw ex;

This article I found in net gives really good insight of it. It suggests to use first method, as it would not truncate previous stack trace information.

C# tips & tricks: String Concatenation, Best practices

When we are struggling with String concatenation issues, specially which is the best way to concatenate the strings. One of my colleague suggested following articles to me.

though this may not be giving every thing you are looking for, but really very nice and worth readable for the .NET developers.

Win32 API listings

I was wondering any one has put win32 api listing online. I googled and found some really useful resources:

Published in: on August 7, 2009 at 11:15 am  Leave a Comment  
Tags: , ,