From: Radical DOT NetSurfer AT delorie DOT com Newsgroups: comp.os.msdos.djgpp Subject: Error trying to Shift Longs & LongLong Date: Wed, 23 Apr 2003 13:31:50 -0400 Organization: Posted via Supernews, http://www.supernews.com Message-ID: X-Newsreader: Forte Agent 1.91/32.564 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse AT supernews DOT com Lines: 57 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com The program below works 100% correctly in Borland, but produces one very obvious problem when run from DJGPP..... x = (1 << m); why should shifting by a (-1) create such an unsual value? Shouldn't shifting by "all" bits give Zero ? Why is the "sign-bit" apparently being shifted into things? Long Long appears to be a special contrivance, so we're not too concerned about their artificial behavior. Comments welcomed! Email to: RadSurfer AT yahoo DOT com ------------------------------------------------------------------------- /* Program to create Binary Table and Complements April 15th, 2003 19:00 */ #include int main(int argc, char **argv) { int x = 0, n = 0, b = 0, p = 0, c = 0, m = 0; //Generate 1 to 2048 for (m=(-1); m<12; ++m) { x = (1 << m); printf("% 5d % 5d ",(m+1), x); for(n=11; n>(-1); --n) { b = (1 << n); p = (x & b); // printf("%d and %d = %d\n", x, b, ( p ? 1 : 0 ) ); printf("%d", ( p ? 1 : 0 ) ); //Foward Binary } printf(" "); c = 0; for(n=11; n>(-1); --n) { b = (1 << n); p = (x & b); printf("%d", ( p ? 0 : 1 ) ); //Inverted Binary if ( !p ) c += b; //Accumulate Non-Zero Values } printf(" % 5d\n", c); //Print Complementary Value } //x++ return(0); } //Main