From: night DOT walker AT tiscalinet DOT it Message-ID: <3922AD5F.EB45FD4D@tiscalinet.it> Date: Wed, 17 May 2000 16:32:00 +0200 X-Mailer: Mozilla 4.7 [en] (WinNT; I) X-Accept-Language: en,pdf MIME-Version: 1.0 To: DJ Delorie Subject: Re: Re: Right shift Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com >night DOT walker AT tiscalinet DOT it wrote: >> Why right-shifting ">>" a negative signed int will first turn it >> positive? >Wrong question, sort of. No. I wanted just to understand how does >> really works, so i used a simple number. Next time i will use 0x04, or 0000 0100, but would be the same thing... >The behaviour of bitshift operations on negative integers is >purposefully left implementation-defined by the C language definition. >For short, that means you should not assume anything about the way it >works. >Bitshifting never was meant to be used for numbers (integers of >any kind), really, it's for collections of bits. >If you wanted / 2, write /2, not >>1. Trust your compiler to >automatically translate that as >>1 if that's a safe and fast method >for the case at hand. If you think you cannot trust your compiler even >that far: why aren't you using a better one? Yes, i know the platform-sensitivity of bit-shifting, but, in the case, i'm working just on a little demo prog. Changing some divisions with right-shifting DOES improve the speed (from 3/4 fps to 4/5 fps on my P90) with no errors. I will be glad to upload you the src (needs ALLEGRO lib). >It's better for your programming skills if you do not know how this is >implemented, so you don't make any silent assumption that will break >if your program ever gets moved to another compiler, operating system >or machine. My prog works perfectly, but, as i do not make any silent assumpion, i was wondering how the da mn thing works, so i made a little test prog... About my prog skill: if i must improve (and i must) let me learn. >Ignorance can protect you, sometimes. I prefer knowledge (do you like aphorisms?) NW