Gerhard Fiedler wrote: >> I just sent how I do it (in C) in another message in this >> thread: >> >> #define HLVDCON_INIT ( /* High/Low Voltage Detection >> */\ (u8) ( >> \ ( 0 << 7) /* (b7) VDIRMAG detection direction (0:det. >> low) */\ | ( 1 << 4) /* (b4) HLVDEN enable detection (1: >> ena) */\ | ( 0b1111 << 0) /* (b3:0) HLVDL3:0 detection >> limit (external) */\ ) >> \ ) > Just a quick point: I'd always advocate using unsigned integer types when doing bitwise operations in C. In your example above, it doesn't matter because the amount of places by which you're shifting is less than "amount of bits in type minus two". If you'd had bigger numbes though, things would've gotten hairy. But take this example though: PORTA &= ~(1u << 3); If this had instead been: PORTA &= ~(1 << 3); then the following would happen: 1) The signed integer 1 gets shifted three places to become signed integer 8 2) The bits of signed integer 8 get flipped, so 0000000000001000 becomes 1111111111110111 (for a 16-Bit int) 3) At this point, the value of the expression is implementation-defined depending on whether the machine's number system is one's complement, two's complement or sign-magnitude. 4) This expression of implementation-defined value must then be converted to an unsigned char to satisfy the assignment to PORTA. Conversions from signed types to unsigned types are well-defined in C, but the problem is that the value we're converting is implementation-defined. So, anyway, you might not get what you asked for if you go with: PORTA &= ~(1 << 3); Also to avoid more problems with signed types, I'd always cast types smaller than int, to unsigned int before doing any operations on them, e.g.: char unsigned a = 7, b = 4; a = ~b; /* Might not get what I want if unsigned char promotes to signed int */ a = ~(unsigned)b; /* Guaranteed to work on every system */ I only every use signed integer types when I explicitly want to store a negative number. They're bad news for bitwise operation. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist