This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

hex values

hello
my question is that i want 16 Byte hex address by combining to 8 byte hex values as follows:

unsigned long addr;
unsigned char buf[3];

buf[0]=0x81;  // msb
buf[1]=0x23;  // lsb
...
printf("%lx", &addr);   //output: addr = 0x8123


i want to retrieve from this array one hex address
into 'addr' variable.
my output is: addr = 0x8123.

thanks in advance

Parents
  • unsigned char buf[4];
    unsigned long addr;
    union split {unsigned int word;
       struct {unsigned char hi;unsigned char lo;} bytes;};
    union split newcount;
    
    buf[0] = 0x81;
    buf[1] = 0x23;
    
    newcount.bytes.hi = buf[0];
    newcount.bytes.lo = buf[1];
    addr = newcount.word;     // output: addr = 0x8123
    
    

Reply
  • unsigned char buf[4];
    unsigned long addr;
    union split {unsigned int word;
       struct {unsigned char hi;unsigned char lo;} bytes;};
    union split newcount;
    
    buf[0] = 0x81;
    buf[1] = 0x23;
    
    newcount.bytes.hi = buf[0];
    newcount.bytes.lo = buf[1];
    addr = newcount.word;     // output: addr = 0x8123
    
    

Children