Search
 
SCRIPT & CODE EXAMPLE
 

C

c bit access struct

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 :: what is strikethrough in markdown 
C :: c int to string 
C :: c fractional sleep 
C :: reverse of a string in c 
C :: how to turn off zsh 
C :: c style array 
C :: puts without newline c 
C :: redirect to url page asp.net mvc 
C :: c program strtok use 
C :: char array to int c 
C :: how to modulo in c without use the operator 
C :: c pass int by reference 
C :: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration] 
C :: c check if array is empty 
C :: c programming how to force stop the programme 
C :: #define arduino 
C :: inputting an array in c 
C :: bootstrap 4 forms 
C :: getchar 
C :: clear screen in c 
C :: bubble sort c 
C :: create node in c 
C :: how to transform a char to ascii code in c 
C :: ex: C hello world 
C :: c defined 
C :: while loop c 
C :: logical operators 
C :: ubuntu ocaml install 
C :: arduino internal pull up resistor 
C :: how tier lists work 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =