We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
How can you access the individual bytes making up a variable of type long? What I need to do is move a 24-bit (3 bytes) unsigned char array into a long variable. An example:
unsigned char a[3]; unsigned long b; a[0] = 0x02; a[1] = 0xFF; a[2] = 0xFF; ????? ?????
Thanks for all the ideas. Since I had a lot of already declared and used variables, a union was pretty much out of the question. Casting the pointer seemed to do the trick just fine. Thanks! James
"Casting the pointer seemed to do the trick just fine." but don't forget that it relies upon C51's internal data representation - so it would be a good idea to do something like Drew's idea to ensure that nobody forgets this and tries to re-use the code on a different target...