We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
bit bitVal; unsigned char byteVal; : : bitVal = byteVal;
bitVal = byteVal & 0x01 // Equivalent to A or bitVal = (byteVal > 0) // Equivalent to B
I'd expect it to be:
bit bitVar; char charVar = 0xA5; bitVar = charVar; // would be interp. as below, e.g. a boolean treatment of charVar. bitVar = !!charVar;
Some cross-compilers handle it differently, and for that reason, I have always performed the byte-to-integer-bit and byte-to-boolean-bit conversions explicitly to handle either case. For example HI-TECH PICC (obviously for Microchip PIC microcontrollers) abides by a more ANSI-like interpretation, remaining faithful to C's integer conversion (narrowing) rules, and implements it like Andrew's example A. If I had ever thought about how bytes *should* be converted to bits, this is the way a "language lawyer" would probably have specified it (i.e., ANSI-like). Regards, --Dan Henry
Take a look at the following thread for an answer to this question. http://www.keil.com/forum/docs/thread1328.asp#Msg5232 Jon
"Take a look at the following thread for an answer to this question." I'd prefer to be able to look in the manual!! How can I say "Please read the manual" if it's not in the F... Manual!!?? ;-)