12 Bit Variable
rlmack33
Posts: 2
I was wondering if anyone knows if there is a way to declare 12 bits (byte + nib) to a variable instead of 16 bits·(word). I don't need 65535, I just need 4095 and would hate to waste 4 bits that could be used someplace else.
Comments
There are a number of methods you might use, but the best method, and answer will only be forthcoming with more information. We need to know more about the specific application.
Please realize I have no knowledge of your programming expertise, so please don't be offended by any of the questions below.
1. Will it be used at ALL within the PBASIC Stamp per se, or is this only for the benefit of some external component? By way of explanation, many external devices require a 12-bit data field be passed to them, rather then an 8-bit (byte) or 16-bit (word) field. This is something of a special case and there are certain techniques for handling these requirements. This technique can often be used for any "odd" (non-nib, non-byte, non-word) number of bits, for external transmission.
2. If it will be used within the PBASIC Stamp per se, will you be doing any math with this "triple nibble"? If so, which mathematical operations (addition, subtraction, multiplication or division)?
3. Will this be a short term or long term use within your program? In other words, is this only used (say) in one routine, and then never needed again, or only needed under certain special circumstances?
3. I trust you realize that not only can variables and variable space in RAM be reassigned and re-used, but aliasing of variable names (multiple use of the same variable space) is also possible and permissable.
4. Based on what was just said in #3, why don't you just use a WORD variable, since after you're done with this "triple nibble", the variable space can be re-used; persuming this is only a short term use.
This should help us zero in on your specfic requirements.
Regards,
Bruce Bates
http://forums.parallax.com/showthread.php?p=560730
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Hope this gives you a beter idea of what I ave trying to do.
I2COUT SDA, slaveAddr, addrHi\addrLo, [noparse][[/noparse]value.BYTE0, value.BYTE1]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax