R
Richard
CBFalconer said:pete said:Army1987 said:anon.asdf wrote:
I want to assign the number 129 (binary 10000001)
to the MSB (most significant byte) of a 4-byte long
and leave the other lower bytes in-tact!Try
((unsigned char *)&val)[3] = 129;
No unions and no struct needed.
You can assign the value of 129
to the highest addressed byte of any object,
this way:
((unsigned char *)&val)[sizeof val - 1] = 129;
Seems to give funny results on my machine. (Which happens to place
the MSByte of an integer in the lowest order address). The world
is not defined by an X86.
But in the context of this question it is.
What is your platform independent solution?
--