what is bit fields in structure | SoloLearn: Learn to code for FREE!

+1

what is bit fields in structure

Hi Can anyone help me to understand importance of bit fields? What does it mean and how it is useful?

6/2/2020 1:33:22 PM

Ketan Lalcheta

9 Answers

New Answer

+9

A bit field is a data structure used in computer programming. It consists of a number of adjacent computer memory locations which have been allocated to hold a sequence of bits, stored so that any single bit or group of bits within the set can be addressed...

+3

A structure or a C++ class can contain bit fields that allow you to access individual bits. You can use bit fields for data that requires just a few bits of storage. A bit field declaration contains a type specifier followed by an optional declarator, a colon, a constant expression, and a semicolon.

+3

Bit field = a uniquely C programming language feature to assign names to certain bit positions in an int typed variable Bit fields are much easier to use than bit operations with & and | operators because: We can access the field by using the field name !

+2

Thanks all for this... I read it but any example would be of great help

+1

U can understood much better read this post https://www.google.com/amp/s/www.geeksforgeeks.org/bit-fields-c/amp/

+1

Bit fields are important for two main reasons: 1.Allows you to manipulate individual bits using a field name.(just as AMOGHA. A. K. has said) 2.unnamed bit fields are used to align the data in structs in a machine dependent way

+1

Finally come up with use case when bit field can be applied to save memory https://code.sololearn.com/c7L891KF9TXI/?ref=app Thanks all of you for your time and help

0

But does this help in structure padding ? If not, what purpose it helps ? And accessing memory is not in our hand.. Isn't it?

0

My structure padding code is below: https://code.sololearn.com/c4na2St2ZDgQ/?ref=app Does bit can be useful here or not? How