avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] typecast


From: Sander Pool
Subject: Re: [avr-gcc-list] typecast
Date: Tue, 25 Mar 2003 15:21:20 -0800

I've been bitten by type conversions quite a bit in the last few weeks, it
seems you really really have to spell it out to gcc to make it do the right
thing. But that's not what you were asking :-)

If you want to have the MSBs of a 16 bit number and stick them in an 8 bit
variable you could do:

number8 = (uint8_t) (number16 >> 8);

This -should- discard the 8 MSBs of the right shifted number, leaving you
the original 8 MSBs from number16.

    Sander

----- Original Message -----
From: "Torsten Hahn" <address@hidden>
To: <address@hidden>
Sent: Tuesday, March 25, 2003 7:33 AM
Subject: [avr-gcc-list] typecast


> Hi,
>
> if i have
>
> uint16_t number16 = 1234;
> uint8_t number8;
>
> number8 = (uint8_t)(number16);
>
> do i get the highest 8 bit from number16 into number8 ? Or is there a
> better (safer) way to geht the most significant byte of an 16, 32 ...
> Bit value ?
>
> by,
> T. Hahn.
>
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]