Thursday, 7 December 2017

Casting Bitwise struct to Integer

I have bitwise structure with a bunch of flags.

struct {
  uint8_t a: 4; 
  uint8_t b: 4; 
} _tVarA

_tVarA Var_A = {0,0};

But when I want to view them as a whole integer, I need to cast it like this:
                               *(uint8_t*)&Var_A

ref:
http://www.avrfreaks.net/forum/casting-bitfield-struct-integer
https://stackoverflow.com/questions/11903820/casting-struct-into-int

No comments:

Post a Comment