P
pranab.salian
I need to compile some newer code in Borland TC 3.0. Here's the
snippet..
/* CODE */
/*
// ---------------------------------------------------------------
// Shift register implementation: Message is divided by G. In the
// reminder, stored in the syndrome register S, are the redundant
// bits.
// ---------------------------------------------------------------
*/
S = 0;
j = K2;
for (i=15; i>=0; i--) {
bit = ( (j & M) >> i ) & 0x01;
j = j>>1;
if (bit)
S = ((S<<1)^FLAG) & NK;
else
S = (S<<1) & NK;
if (S & FLAG)
S = (S^G) & NK;
}
/* At this point a watch on "S" says S:119, and S,x:0x77 */
/* Write the generator matrix of the code: */
printf("%4x %3lx", M, S);
/* END CODE */
I had to change most int variables to long int for the code to even run
properly when compiled with TC 3.0. Now the problem is when the printf
converts the long S to hex, instead of the expected "77" it prints
"770000". I need a way to stop it from printing the trailing zeroes.
Oh BTW it is "lx" in "%3lx" because for some reason I can't figure, if
I use "%3x" it just prints a "0". I would expect it to print "77".
snippet..
/* CODE */
/*
// ---------------------------------------------------------------
// Shift register implementation: Message is divided by G. In the
// reminder, stored in the syndrome register S, are the redundant
// bits.
// ---------------------------------------------------------------
*/
S = 0;
j = K2;
for (i=15; i>=0; i--) {
bit = ( (j & M) >> i ) & 0x01;
j = j>>1;
if (bit)
S = ((S<<1)^FLAG) & NK;
else
S = (S<<1) & NK;
if (S & FLAG)
S = (S^G) & NK;
}
/* At this point a watch on "S" says S:119, and S,x:0x77 */
/* Write the generator matrix of the code: */
printf("%4x %3lx", M, S);
/* END CODE */
I had to change most int variables to long int for the code to even run
properly when compiled with TC 3.0. Now the problem is when the printf
converts the long S to hex, instead of the expected "77" it prints
"770000". I need a way to stop it from printing the trailing zeroes.
Oh BTW it is "lx" in "%3lx" because for some reason I can't figure, if
I use "%3x" it just prints a "0". I would expect it to print "77".