Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Bit Fields in C

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 81
    Comment on it

    To provide manipulation in a single bit of data or into the multiple bits we will use the things for these bit manipulation.

     

    struct {
       unsigned int widthValidated;
       unsigned int heightValidated;
    } status;

     

    This will give you the total size occupied by the data type included in this structure as a combine.

     

    #include <stdio.h>
    #include <string.h>
    
    /* define simple structure */
    struct {
       unsigned int widthValidated;
       unsigned int heightValidated;
    } status1;
    
    /* define a structure with bit fields */
    struct {
       unsigned int widthValidated : 1;
       unsigned int heightValidated : 1;
    } status2;
     
    int main( ) {
    
       printf( "Memory size occupied by status1 : %d\n", sizeof(status1));
       printf( "Memory size occupied by status2 : %d\n", sizeof(status2));
    
       return 0;
    }

     

     

    Elements Description
    type An integer type that determines how a bit-field's value is interpreted. The type may be int, signed int, or unsigned int.
    member_name The name of the bit-field.
    width The number of bits in the bit-field. The width must be less than or equal to the bit width of the specified type.

     

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: