|
Assigning a larger value to a bitNext Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author Andrew Neil Posted 5-Mar-2002 06:02 Toolset None |  Assigning a larger value to a bit Andrew Neil
bit bitVal;
unsigned char byteVal;
:
:
bitVal = byteVal;
Question: How does C51 determine whether to set or clear the bit? Does it: A). Simply copy the LSB of the byteVal into the bit, or B). Clear the bit if the byteVal is zero; set it otherwise
ie,
bitVal = byteVal & 0x01 // Equivalent to A
or
bitVal = (byteVal > 0) // Equivalent to B
It looks like it does B, and that seems to me to be the most reasonable for an "arithmetic" assignment; but I'd just like to be sure. I couldn't see it in the manual.
| | Read-Only Author Mark Odell Posted 5-Mar-2002 13:42 Toolset None |  RE: Assigning a larger value to a bit Mark Odell 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;
Regards,
- Mark
| | Read-Only Author Dan Henry Posted 5-Mar-2002 14:30 Toolset None |  RE: Assigning a larger value to a bit Dan Henry 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 | | Read-Only Author Jon Ward Posted 12-Mar-2002 11:02 Toolset None |  RE: Assigning a larger value to a bit Jon Ward Take a look at the following thread for an answer to this question.
http://www.keil.com/forum/docs/thread1328.asp#Msg5232
Jon | | Read-Only Author Andrew Neil Posted 12-Mar-2002 14:10 Toolset None |  RE: Assigning a larger value to a bit Andrew Neil "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 "RTFM" if it's not in the F... Manual!!?? ;-)
| |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|