[Icc-avr] Casting
John Baraclough
j_baraclough at zetnet.co.uk
Sat Jan 12 07:38:48 PST 2008
Andrew wrote:
> Hi,
>
> When casting and int to two char' (a MSB and LSB) is it safe to do the
> following:-
> Data[7] = (Channel_One >> 8);
> Data[8] = (Channel_One);
>
No
> Or am i best doing: -
>
> Data[7] = ((unsinged char)Channel_One >> 8);
> Data[8] = ((unsinged Char)Channel_One);
>
Yes, but you need to adjust your parentheses and spelling.
> or
>
> Data[7] = (((unsigned char)(Channel_One & 0xF0)) >> 8 );
> Data[8] = (Channel_One & 0x0F);
>
No, because Data[7] will always be 0 and Data[8] should be cast and will
have a maximum value of 15.
>
>
> Andy
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
>
>
HTH
John
More information about the Icc-avr
mailing list