Top Answer
User Avatar
Wiki User
Answered 2009-01-18 11:30:13

Both C and C++ allow integer members to be stored into memory spaces smaller than the compiler would ordinarily allow. These space-saving structure members are called bit fields, and their width in bits can be explicitly declared. Gagandeep Singh Bitfields can only be declared inside a structure or a union, and allow you to specify some very small objects of a given number of bits in length. struct { /* field 4 bits wide */ unsigned field1 :4; /* * unnamed 3 bit field * unnamed fields allow for padding */ unsigned :3; /* * one-bit field * can only be 0 or -1 in two's complement! */ signed field2 :1; /* align next field on a storage unit */ unsigned :0; unsigned field3 :6; }full_of_fields; The main use of bitfields is either to allow tight packing of data or to be able to specify the fields within some externally produced data files.

User Avatar

Your Answer

Still Have Questions?

Related Questions

Can you enter data in design view in ms access?

No. Design view is for creating the table and manipulating the fields and the structure of the fields and the table. It is not for entering data. To do that you can go to datasheet view or use a form.

What weaponds did the Declaration of Independence use?

the declaration of independence is a piece of paper. it did not use weapons.

How do you use the word fields in a sentence?

These fields of flowers are stunning.

How do you use Declaration in a sentence?

Thomas Jefferson wrote the Declaration of Independence.

What is the term for a structure that has no use in an organism?

Vestigial StructureA vestigial structure is a structure that appears to no longer have a use in the body.

Use the Declaration of Independence in a sentence?

the declaration of independence was signed July 4th

How can you use the word declaration in a sentence?

The declaration was made in front of a large audience.

How do you use declaration of independence sentence?

The Declaration Of Independence was signed July 4th

Did the military use mine fields in the Korean war?

Yes mine fields where used but they were magnetic mine fields.

How did the Ancient Egyptians use irrigation to water their fields?

The Ancient Egyptians irrigated their fields by making ditches from the dam to their fields.

What is the use of bit field in structure declaration?

A bit field allows you to assign an arbitrary number of bits to a member. As an example, suppose we wish to implement an R6000 PPN (physical page number). A PPN is a 32-bit value divided up as follows: page frame number (22 bits) unused (3 bits) cache coherency algorithm (3 bits) nonreachable (1 bit) dirty (1 bit) valid (1 bit) global (1 bit) While we could use bitwise logic to determine the state of each bit or group of bits within a 32-bit value, it's always good programming practice to express ideas directly in code. Therefore we want a structure that is exactly 32-bits in length with members that exactly match those of the PPN itself. To achieve this we need to use bit fields: // // All example code based upon Chapter 25.5.5 "Bitfields" of // "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup // struct PPN { // R6000 Physical Page Number unsigned int PFN : 22; // Page Frame Number int : 3; // unused unsigned int CCA : 3; // Cache Coherency Algorithm bool nonreachable : 1; bool dirty : 1; bool valid : 1; bool global : 1; }; Any consumer of this structure need be left in little doubt regarding its purpose. Moreover, the implementer's job is greatly simplified: void part_of_VM_system (PPN& ppn) { if (ppn.dirty) { // contents changed // copy to disc ppn.dirty = 0 ; } } We can also see how much simpler it is to extract information from a structure's bit fields compared to that of a 32-bit value: int get_CCA (const PPN& ppn) { return (int) ppn.CCA; } int get_CCA (unsigned int ppn) { return (int) (ppn>>3)&0x7; }

Does the Declaration of Independence use induction or deduction?

The Declaration of Independence uses DEDUCTIVE thinking

How do you use declaration in a senence?

Declaration is the act of declaring. The Kitten made his declaration that all cats must loved!!! Cats Rule!!!

What is difference between Near structure and far structure?

We haven't used near and far addressing for well over a decade. It was common in older systems where memory was addressed by segment and offset. For instance, on a 32-bit system we might use 16-bits to address the segment and 16-bits to address the offset within that segment. If we were referring to an offset within the current segment then we'd use a 16-bit near pointer, but if we needed to refer to another segment then we'd use a 32-bit far pointer. Today we use a normalised pointers.

What tool does scientist use to find magnetic fields?

A magnetometer detects magnetic fields.

Use of canals to bring water to crop fields?

The use of canals to bring water to crop fields is called 'irrigation' or 'irrigating'.

What is a homologous structure?

A homologous structure is a similar structure but has a different use. ex. birds use filanges to fly while people use them for other purposes

What drill bit you use for a 0.875 hole?

You use a 0.875 bit or a 7/8 bit . They are the same size.

Why do farmers use quicklime?

they use it to neutralise acidic soil in fields

What did ancient farmers use to bring water to their fields?

They used levee canals to bring water to their fields.

A structure that has no use in the organism in which it is found is called what?

A vestigial structure is one that has no use in the organism in which it is found.

Doesn't oiling a hot drill bit change the molecular structure making it brittle and requiring oiling each use thereafter?

In most cases I wouldn't think the bit would get hot enough to change the temper or heat treat of it. When drilling you should always use some kind of cutting oil to aide in the removal of chips and to keep the bit cool.

What is the difference between bit code and byte code?

Byte code typically uses fixed-width 8-bit groupings (bytes), whereas bit code can use any combination of fixed-length and variable-length groupings. Data is typically read 1 bit at a time, such that the initial bits determine the structure of the stream of bits that follow.

Still have questions?

Trending Questions
How to Make Money Online? Asked By Wiki User
Best foods for weight loss? Asked By Wiki User
Does Neil Robertson wear a wig? Asked By Wiki User
Unanswered Questions