Hi! i want to spilt the 16bit word into two 8bit words, is there any key words for it. i use the p89V51 mcu and c language Cx51 keil compiler ver3.
regards, K.T.Venkatesan.
If you don't want shift and/or mask you can also use division and modulus
e.g.,
int Value; char Hi; char Lo; Value = 0x1234; Hi = Value/0x100; Lo = Value%0x100;
Ah yes - that makes four!
Of course, division by a power of two is equivalent to shifting.
I can't see any advantage of division & modulus over shift & mask - and there is the distinct possibility that it will be grossly inefficient if the compiler does actually implement it as the maths functions...
Hi! that's nice to use this method.Thank you matt and Neil.
"I can't see any advantage of division & modulus over shift & mask ..."
Right-shifting an int having a negative value is implementation-defined, whereas div/mod are not.
It would be nice if that were true, but actually this only holds if your compiler claims compliance to C99.
In the original standardized version of the language, C90, which still has to be considered the default assumption for portable code, division of negative numbers is implementation-defined, too. (-1)/2 can yield either -1 or 0; (-1)%2 can be either -1 or 1.