I sucked bitwise operators until I learned to read binary well, and read through this:
http://www.cprogramming.com/tutorial/bitwise_operators.html
Along with the power of two exercise at the end of that article, heres a few more I did from the C Programming Language that are good ways to keep in practice and get solid with them, though I rarely end up using them:
Exercise 2-6. Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position
p set to the rightmost n bits of y, leaving the other bits unchanged.
Exercise 2-7. Write a function invert(x,p,n) that returns x with the n bits that begin at position p
inverted (i.e., 1 changed into 0 and vice versa), leaving the others unchanged.
Exercise 2-8. Write a function rightrot(x,n) that returns the value of the integer x rotated to the
right by n positions.
I can give you the solutions if you want :)
Also you can abbreviate your code with on 8-13 with the ?: operator :)
|
sex = (sex == m) ? 1 : 0;
|