HELP: Understanding basic C and bitfields...


hey,

ok not few things , must resort begging assistance. :p

first off, point of caring variable's address? shouldn't environment take care of that, that's intended ide? don't see purpose referencing &variable for, please explain?

secondly, how manipulate packed bit fields? let me give example , see if have clue:

code: [select]
struct hours_byte
{
unsigned int format: 1;     // range: 0-1, 0=24h 1=12h
unsigned int ampm: 1;       // range: 0-1, 0=am 1=pm
unsigned int tenshours: 2;  // range: 0-2
unsigned int hours: 4;      // range: 0-15 (guessing never goes on 9)
};


so in case, interfacing rtc, hours broken , tens of hours separate field? 2am 00000010, 11pm 00100011? understand this, when translated bin hex, 2 , 23, respectively. seems stupid me comprehension not come easily. why? , if hours field 4 bits, means possibly go on 9, have write check routine since in layout, 11am both 00010001 or 00001011 ?

i guess main point this: how manipulate individual bits in bitfield, both reading , writing?

thanks reading.

quote


first off, point of caring variable's address? shouldn't environment take care of that, that's intended ide? don't see purpose referencing &variable for, please explain?


this because if want send of large scale. object 200 bytes, if not pass adress, processor need copy bytes, instead of adress.

actually pretty clever.

pointers

quote

secondly, how manipulate packed bit fields? let me give example , see if have clue:

code: [select]
struct hours_byte
{
unsigned int format: 1;     // range: 0-1, 0=24h 1=12h
unsigned int ampm: 1;       // range: 0-1, 0=am 1=pm
unsigned int tenshours: 2;  // range: 0-2
unsigned int hours: 4;      // range: 0-15 (guessing never goes on 9)
};


i guess main point this: how manipulate individual bits in bitfield, both reading , writing?


you should adress struct other structs:

code: [select]
mystructinstance.myfield = var;
code: [select]
var = mystructinstance.myfield;

as manipulating bits see: http://arduino.cc/en/reference/bitset , http://arduino.cc/en/reference/bitread
:)


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > HELP: Understanding basic C and bitfields...


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums