[Icc-avr] AW: Icc-avr Digest, Vol 42, Issue 23
Jörg Linden
jl at linden-edv.de
Sat Jan 12 13:06:44 PST 2008
Hi,
why you dont use a union like this
typedef struct {
unsigned char L;
unsigned char H;
} ByteField;
typedef union {
unsigned int Ui;
ByteField Byte;
} Int2Bytes;
typedef union {
unsigned int Ui;
long Lng;
} IntBytes;
Then you define your data field
IntBytes Channel_One
and change this code
Data[7] = (Channel_One >> 8);
Data[8] = (Channel_One);
into this
Data[7] = Channel_One.Byte.H;
Data[8] = Channel_One.Byte.L;
Joerg
-----Ursprüngliche Nachricht-----
Von: icc-avr-bounces at imagecraft.com
[mailto:icc-avr-bounces at imagecraft.com] Im Auftrag von
icc-avr-request at imagecraft.com
Gesendet: Samstag, 12. Januar 2008 21:01
An: icc-avr at imagecraft.com
Betreff: Icc-avr Digest, Vol 42, Issue 23
Send Icc-avr mailing list submissions to
icc-avr at imagecraft.com
To subscribe or unsubscribe via the World Wide Web, visit
http://dragonsgate.net/mailman/listinfo/icc-avr
or, via email, send a message with subject or body 'help' to
icc-avr-request at imagecraft.com
You can reach the person managing the list at
icc-avr-owner at imagecraft.com
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Icc-avr digest..."
Today's Topics:
1. Casting (Andrew)
2. Re: Casting (John Baraclough)
----------------------------------------------------------------------
Message: 1
Date: Sat, 12 Jan 2008 10:40:04 -0000
From: "Andrew" <andrew_166 at msn.com>
Subject: [Icc-avr] Casting
To: "Discussion list for ICCAVR and ICCtiny Users. You do NOT need
tosubscribeto icc-announce if you are a member of this."
<icc-avr at imagecraft.com>
Message-ID: <BLU123-DAV71A63AD833FEEBAF6CA5BA0440 at phx.gbl>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=response
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);
Or am i best doing: -
Data[7] = ((unsinged char)Channel_One >> 8);
Data[8] = ((unsinged Char)Channel_One);
or
Data[7] = (((unsigned char)(Channel_One & 0xF0)) >> 8 );
Data[8] = (Channel_One & 0x0F);
Andy
------------------------------
Message: 2
Date: Sat, 12 Jan 2008 15:38:48 +0000
From: John Baraclough <j_baraclough at zetnet.co.uk>
Subject: Re: [Icc-avr] Casting
To: "Discussion list for ICCAVR and ICCtiny Users. You do NOT need to
subscribe to icc-announce if you are a member of this."
<icc-avr at imagecraft.com>
Message-ID: <4788DF08.1010709 at zetnet.co.uk>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
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
------------------------------
_______________________________________________
Icc-avr mailing list
Icc-avr at imagecraft.com
http://dragonsgate.net/mailman/listinfo/icc-avr
End of Icc-avr Digest, Vol 42, Issue 23
***************************************
More information about the Icc-avr
mailing list