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
  • "i want 16 Byte (sic?) hex address by combining to 8 byte (sic?) hex values"

    Don't you mean a 16-bit (ie, 2-byte) value from two 8-bit (ie, 1-byte) values?!

    Note that "hex" is irrelevant here - they are just values.

    There are 3 approaches:

    1. Use the standard 'C' shift operator;

    2. Use a union;

    3. Use a pointer, and cast it appropriately.

Reply
  • "i want 16 Byte (sic?) hex address by combining to 8 byte (sic?) hex values"

    Don't you mean a 16-bit (ie, 2-byte) value from two 8-bit (ie, 1-byte) values?!

    Note that "hex" is irrelevant here - they are just values.

    There are 3 approaches:

    1. Use the standard 'C' shift operator;

    2. Use a union;

    3. Use a pointer, and cast it appropriately.

Children
No data