Skip to content

Instantly share code, notes, and snippets.

@pancurster
Created March 3, 2012 10:24
Show Gist options
  • Save pancurster/1965405 to your computer and use it in GitHub Desktop.
Save pancurster/1965405 to your computer and use it in GitHub Desktop.
Przykładowe użycie pól bitowych do sterowania crosspointami
#include <stdio.h>
#include <malloc.h>
#define uint8_t (unsigned char)
int main (int argc, char const* argv[])
{
typedef struct _cross_setting {
unsigned char IN0:2;
unsigned char IN1:2;
unsigned char IN2:2;
unsigned char IN3:2;
}CS;
CS* ustawienie = malloc(sizeof(ustawienie));
ustawienie->IN0 = 0x03;
ustawienie->IN3 = 0x01;
printf("%x, size: %d\n", *(int*)ustawienie & 0x000000FF, sizeof(*ustawienie));
CS crosspointy = {0};
crosspointy.IN2 = 3;
crosspointy.IN3 = 1;
printf("size: %d\n", sizeof(crosspointy));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment