The Psychology of Quality and More |
CHAPTER 9 : Data Usage
9.9 Using bit structuresBit structures are typically used where space is at a premium, or where hardware registers must be matched. Style-wise the bits used give a message about the maximum size of the contained number:
struct --------------------------------------------------------------- Bit structures, however, are highly non-portable. There is also a danger of only a loose functional relationship between the structure elements - the common factor being the reduced bit usage. They may also have a significant performance cost. 9.9.1 Bit Structures vs. Bit operatorsAn alternative to bit structures is to directly use bit operations, where masks and boolean operations are used to access fields. This may be more efficient, but it is seldom as clear. The equivalent of accessing Window.Width in the above example is:
WindowWidth = (WindowBits & WIN_WIDTH_MASK) >> WIN_WIDTH_POSN;
Bit operations do allow operations to be combined. Bit structures, on the other hand are clearer in use, and may allow structures larger than words. Thus they are usually preferable. If, however a bit-layout is defined in a program interface, then using bit operations is a more portable method.
|
Site Menu |
Quality: | Quality Toolbook | Tools of the Trade | Improvement Encyclopedia | Quality Articles | Being Creative | Being Persuasive | |
And: | C Style (Book) | Stories | Articles | Bookstore | My Photos | About | Contact | |
Settings: | Computer layout | Mobile layout | Small font | Medium font | Large font | Translate | |
You can buy books here |
And the big |