I'm having a little bit of trouble with bitwise operations in C and I was wondering if someone could walk me through a problem. Basically, given a 32 bit number (int), how could I select a specific byte (0, 1, 2, 3) of the number? The int is signed in this case as well.

Logically AND it to another 32 bit int which has the byte you're interested in full of ones and the rest full of zeros. (If you think about that, it makes sense. If you AND something to zero you'll ALWAYS get zero, only when you AND to one do you get one.) I wish I could give you the code, but I haven't done this stuff in...ever.

http://en.wikipedia.org/wiki/Bitwise_operation You can use a bit mask. number: 0101 bitmask: 0001 Now we can use a bitwise AND to discover what the right most bit is. The trick is that the right most bit of the bitmask is 1. Remember, we need two 1's in the bitwise AND operation for the result to be 1. So the bitwise AND can give us what the unknown is. After you "extract" a bit, you can do a bitwise shift and do another bitwise AND operation with the same mask to get the next bit.

I'm a total newbie to C, if it hasn't already hit you in the face. The next problem is to write a function that takes in 4 ints representing dotted-decimal notation and returns the unsigned integer, i.e., (1,2,3,4) returns (16909060).

shift the first number over 24, second number over 16, third 8 and add the fourth Code: unsigned int ddn(unsigned int num1, unsigned int num2, unsigned int num3, unsigned int num4) { return( (num1 << 24) + (num2 << 16) + (num3 << 8) + num4); }

Kernighan and Ritchie The C Programming Language written by the guys who wrote C (or one of 'em did anyway) back in the stone age - when I was programming. T'was THE reference for C programming back then.

bitwise stuff is difficult to figure out at first because you don't really use it in application programming too much besides some calculation optimization stuff that is sometimes faster. Any kind of low level programming uses bit operations alot. I didn't get good with it until I started doing assembly alot.

. Unless you're a computer engineering major, I don't think you'll get too much into bitwise calcs. CompEng makes you get into it early and often though.