hello friend 
noticing that my previous post was too short and complicated to understand i 
have decided to give a better reply to you. unions save a lot of time and 
handle complicated tasks easily and urs seems similar to that so here is a 
simple example of unions for you with its output:

unions.c:
========================================

#include <stdio.h>

union vals {
    unsigned short x;
    unsigned char y[1];
} myvals;

int main() {
    myvals.y[0] = 1;  //lsb  -- 00000001
    myvals.y[1] = 21; //msb --00010101

    printf("%d", myvals.x); // displaying 16 bit uint 0001010100000001
    printf("\n %d", sizeof(myvals));
}

==========================================
and its output is :

5377
 2

The size of a union is equal to the size of it's largest data member. in this 
case it is 2 bytes bcoz of 16bit uint. and the uint and the array of char share 
the same memory space. hence using array of 2 1 byte uchars we can easily 
access the lsb and msb of the uint.
i hope you understand this time what i am trying to say and this works for you 
too. sorry for the last post which was not very useful. i was using borland 
turbo c++ 3.0's c compiler on my machine. 

bdrmachine <[EMAIL PROTECTED]> wrote:                                  Can 
someone give me a C example of how to combine 2 unsigned chars (msb 
 and lsb) and store as a unsigned int (L)? It seams the technique I'm 
 using is more involved then it should be. Would "L= msb<<8 + lsb;" 
 work?  I'm working on a program for a 8 bit microcontroller. Unsigned 
 char's are 8 bits long and unsigned int's are 16 bits.
 
 Thanks
 Brian  
 
 
     
                  



       
---------------------------------
Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV. 

[Non-text portions of this message have been removed]

Reply via email to