X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Mok-Kong Shen Newsgroups: comp.os.msdos.djgpp Subject: bit shifting problem Date: Wed, 09 Feb 2005 23:07:02 +0100 Organization: T-Online Lines: 26 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.t-online.com 1107986688 00 23595 K2CQrh1L97nrSXGe 050209 22:04:48 X-Complaints-To: usenet-abuse AT t-online DOT de X-ID: EejvXaZVwetWeVcYdP-rP-K+9usH1WK3CjJbxXU3m8WpzvVpLLX5ZK User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Sorry for posing yet another, possibly also newbie, problem. In the following code I expected the values of k and n to be both 0, since shifting 32 bits for a 32-bit word effectively clears it. But the values printed were 42800637 and 1369620384. The compiler did give the warning message "right shift count >= width of type". But shifting 32 bits (not exceeding the word size) is allowed or is it forbidden by the C standard? Thanks. M. K. Shen -------------------------------- #include int main() { int i,j,k,n; unsigned long w; w=42800637; i=w>>31; j=i>>1; k=w>>32; n=(w<<5)>>32; printf("%lu %d %d %d %d\n",w,i,j,k,n); return 0; }