answersLogoWhite

0


Best Answer

We can define structure bit field members with Dot operators.

EXAMPLE:

#include <stdio.h>

int main()

{

Struct bit_field

{

Int x.4; // it allocates only 4 bits to x

Char C.6; // it allocates only 6 bits to C;

};

return 0;

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

in paking of data

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you define a structure with bit field members?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why bit masking is required in c language?

Bit masking is required whenever we need to invert a group of bits in a bit field. Bit masks allow us to perform these changes in a single operation rather than one bit at a time.


What is a 8085 microprocessor?

with neat diagram explain the system bus structure of 8085


Difference between class and structure in csharp?

I'm not sure about csharp, but in OO a class has a state and behaviour whereas structure has only state.The state of a class is the data members, or attributes of a class. Behaviour of a class is the function members, or the methods of a class. Ie, a class has attributes and functions, but a struct has only attributes.Historically, classes derived from structures. At one point someone thought of adding behaviour or functionality to structures and the resulting type was called a class.I'll give you an example.struct Student {//stateint YearInCollege;};This structure has only data members that can be manipulated in the program. Eg:Student You;You.YearInCollege=1; //change state...int a=You.YearInCollege; //read stateAs you can see, we can read and write the members of a structure as we wish.Now, let's give the structure a bit of functionality.class Student {//behaviourint WhatsMyYearInCollege(void);void ChangeMyYearInCollege(int);//stateint YearInCollege;};as you can see, now besides the state we also have functionality to change the state of the class. Now, we'll change the state of the class only through its own member functions, also called mutator functions. Eg:Student You;You.ChangeMyYearInCollege(2); //change state through class' own function...int a=You.WhatsMyYearInCollege(); //read state through class' own function


Is it possible to change the data type for a field that already contains data?

You can change the data type of an existing field using a union, however, you should understand that bit format dependance is not portable usage, and that you should initialize the field every time you change your desired type.Answer: without specifying the context, this question cannot be answered.


How are the data elements of a structure accessed and processed explain?

The data elements of a structure are laid out according to the order they are declared. Padding bytes may also be inserted between members to ensure all members are correctly aligned. Memory alignment can be user-defined, however it's generally better to align objects according to the underlying architecture. For instance, on a 32-bit system the underlying architecture has a 4-byte word length, thus an object that is equal or greater in length is best aligned upon a 4-byte boundary to keep memory access cycles to a minimum. Types that are smaller than the word length are usually aligned so that they do not cross a word boundary, such that a single 4-byte word can store 4 char types, 2 shorts, or 2 chars and 1 short. If the total size of the structure crosses a word boundary, padding bytes are inserted after the final member so the total size is an exact multiple of the word length. However, if the total size is less than a single word length to the extent that two or more structures may fit within a word, no padding bytes are required. Given that each structure member is positioned at a constant zero-based offset from the start address of the structure, the compiler can use trivial pointer arithmetic to access the individual members of an instance of the structure, just as easily as it can calculate the address of an array element from its zero-based suffix (index).

Related questions

What are bit fields What is the use of bit fields in a Structure declaration?

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.


Fee structure of Anna university BIT campus?

fees structure of anna univ. bit campus


What is define real number?

It is a bit hard to define them - and the exact definitions are a bit formal. It is best to think of real numbers as the equivalent of all points on a straight line, infinite in both directions.


Define the term ruminants?

Ok let me ruminate on that for a bit, It is an aminal with 4 compartments in its gut.


Which is sronger shell structure or solid structure?

Solid Structure because a Solid Structure is Solid all the way through and Shell structures are a little bit easier to destory. JAB&lt;3


Similarities between union structure enum in c?

Structures and unions share the following characteristics: * Their members can be objects of any type, including other structures and unions or arrays. A member can also consist of a bit field. * The only operators valid for use with entire structures and unions are the simple assignment (=) and sizeof operators. In particular, structures and unions cannot appear as operands of the equality ( == ), inequality (!=), or cast operators. The two structures or unions in the assignment must have the same members and member types. * A structure or a union can be passed by value to functions and returned by value by functions. The argument must have the same type as the function parameter. A structure or union is passed by value just like a scalar variable; that is, the entire structure or union is copied into the corresponding parameter. similarity is all three are user defined data types.


A computer with a 32-bit address uses a two-level page table Virtual addresses are split into a 9-bit top-level page table field an 11-bit second-level page table field and an offset How large are?

11bit


Define bit in microprocessor?

: A Bit is a digit in the binary number system. It can have two values, 0 or 1. In computer RAM and ROM memory, a bit is a small electrical switch which is either on (value 1) or off (value 0).


How do you define a hobo spider?

a hobo spider is brown and hairy you will know if you got bit by it if you see a huge blister from the spider


Who are the members of greasers?

Ponyboy, Johnny, Darry, Dally, Soda, Steve, and Two-bit


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&amp; 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&amp; ppn) { return (int) ppn.CCA; } int get_CCA (unsigned int ppn) { return (int) (ppn&gt;&gt;3)&amp;0x7; }


Is the Barcelona football field bigger than any other?

The field is 68 meters wide and 105 long. This makes it by far the widest field in topfootball, and a bit of cheating