??? 11/16/07 16:49 Read: times Msg Score: -2 -1 Answer is Wrong -1 Message Not Useful |
#147078 - my explanation Responding to: ???'s previous message |
If you need to define a lot of values, use bits. ... That just makes no sense at all! I will explain my thinking by example: Suppose you made a program that stores information about a user and what he is to a retail company. Also, [u]assume[/u] that the program checks for the following conditions: Did user pay on time? Did user pay in full? Does user exist? Is the user an owner? Is the user trustworthy? Is user paying by cash? Does user need to be audited? Can user modify extra settings? As you can see, each of these questions will likely produce two obvious answers. They are YES, and NO. 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. Why? because 1) it saves memory (you get 7 bits freed for each question like this), 2) an answer can only be one of two values. Since a bit can contain only two values (0, and 1), it would make sense to make YES = 1, and 0 = no. So, in memory, if the answers to the questions above are yes, then you can store "11111111" in one byte of external memory. If the last 3 questions had the answer NO, then you could store "11111000" in one byte of external memory. storing "11111000" in one byte is better than storing: 00000001 00000001 00000001 00000001 00000001 00000000 00000000 00000000 in 8 bytes. Many would store each question in 1 byte, but you are wasting bits that way. I am referring to external memory, not internal memory. If I still confuse anyone, I will explain further. |