??? 11/16/07 17:55 Read: times |
#147082 - You need to think more carefully before you write Responding to: ???'s previous message |
You need to think more carefully, and make it clear where you're talking in general, and where you're making a specific, specialised point.
Mike Stegmaier said:
If you need to define a lot of values, use bits. I said:
That just makes no sense at all! OK, so what you said makes sense only if you are talking about binary values As you can see, each of these questions will likely produce two obvious answers. They are YES, and NO. Exactly: binary values - which is the one and only, special case where this can make any sense. Some people might think that one byte of memory can store each answer. Yes, it is OK, but not practical. You should use one bit to store the answer of each question instead of one byte. Not necessarily. If your processor doesn't have the facility to directly access individual bits, then there's going to be an overhead in isolating the bits from the byte Depending on your particular requirements, it may be more advantageous to "waste" some memory rather than suffer this overhead. There may be other issues; eg, if you want an array of flags, or if you want to pass individual flags as function parameters, etc... Since a bit can contain only two values (0, and 1), it would make sense to make YES = 1, and 0 = no. There you go again - it might equally make sense to have Yes=0 and No=1 So, in memory, if the answers to the questions above are yes, then you can store "11111111" in one byte of external memory. And again - it is entirely irrelevant whether the memory is internal or external! storing "11111000" in one byte is better than storing:
00000001 00000001 00000001 00000001 00000001 00000000 00000000 00000000 Again, this is not necessarily "better" - see above. I am referring to external memory, not internal memory. Again, that is entirely irrelevant! Of course, in the specific case of an 8051, you have bit manipulation instructions, and bit-addressable objects - so that would be the way to go for this particular case. |