Ways to divide the high/low byte from a 16bit address?

Posted by Grissiom on Stack Overflow See other posts from Stack Overflow or by Grissiom
Published on 2010-03-29T14:24:19Z Indexed on 2010/03/29 14:33 UTC
Read the original article Hit count: 280

Filed under:

Hello,

I'm developing a software on 8051 processor. A frequent job is to divide the high and low byte of a 16bit address. I want to see there are how many ways to achieve it. The ways I come up so far are: (say ptr is a 16bit pointer, and int is 16bit int)

ADDH = (unsigned int) ptr >> 8;
ADDL = (unsigned int) ptr & 0x00FF;

and


ADDH = ((unsigned char *)&ptr)[0];
ADDL = ((unsigned char *)&ptr)[1];

Does anyone have any other bright ideas? ;)

And anyone can tell me which way is more efficient?

© Stack Overflow or respective owner

Related posts about c