Search
 
SCRIPT & CODE EXAMPLE
 

C

c bit access union

typedef union a429_tag { // define a union of structs and/or raw data types
  // struct to access each bit individually
  struct {
    unsigned int
        bit0  : 1, bit1  : 1, bit2  : 1, bit3  : 1,
        bit4  : 1, bit5  : 1, bit6  : 1, bit7  : 1,
        bit8  : 1, bit9  : 1, bit10 : 1, bit11 : 1,
        bit12 : 1, bit13 : 1, bit14 : 1, bit15 : 1;
  };
  // struct to access range of bits by name
  struct {
    unsigned int
        label  : 8,
        sdi    : 2,
        data   : 3,
        ssm    : 2,
        parity : 1;
  };
  // int type to access to the entire word as an integer
  unsigned int word : 16;
  
} a429_type;

/* Example usage */
int main() {
  a429_type myUnion;
  myUnion.parity = 1;
  if (myUnion.bit15 == 1) {
    printf("parity and bit15 refer to the same bit");
  }
  return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: servo motor arduino 
C :: c convert integer to string 
C :: c float to string 
C :: what is covert channel 
C :: how to empty string in c 
C :: how to create calculator with switch in c 
C :: check prime number or not c 
C :: arduino millis 
C :: c programing strtok use 
C :: fopen function in c 
C :: downgrade chrome to previous stable version in linux 
C :: PATH_MAX 
C :: int_min in c 
C :: Firebase Connecting with ESP8266 
C :: format specifiers in c 
C :: c program to find the frequency of all characters in a string 
C :: sqlserver insert with set identity 
C :: HOW TO ADD FORM IN BOOTSTRAp 
C :: latex remove page number from footer 
C :: c bits 
C :: millis() 
C :: pop and push shows black screen which needs to be pressed back flutter 
C :: Float and Double Input/Output 
C :: mediawiki upload size 
C :: check if string contains a character in c 
C :: bool c++ 
C :: logical operators in c 
C :: use frama c online 
C :: voide means in c 
C :: string text line 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =