Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: logical shift operation

2009-06-27 by stevech11

re
 c1 = (unsigned char)i1>>2;

I make a habit of coding as below to make operator precedence explicit:
 c1 = (unsigned char)(i1>>2);


--- In AVR-Chat@yahoogroups.com, Антощенков Роман Ð'икторович <djantoxa@...> wrote:
>
> Hello!
> 
> Problem solved. It is my fault.
> 
> >> i1 = 1024;
> >> i2 = i1 >> 2;
> >> c1 = (unsigned char)i1>>2;
> >>
> >> Why c1 = 0? Must be c1 = 256!
> 
>  i1 = 1023; !
>  i2 = i1 >> 2;
>  c1 = (unsigned char)i1>>2;
>  c1 = 255 !
> -- 
> Best regards,
> Roman Antoshchenkov
> mailto:djantoxa@...
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.