Mail Archives: djgpp/2003/04/23/13:30:04.1
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 <stdio.h>
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
- Raw text -