I'm converting some C code that calculates a CRC-16 value for a string, and then
generates two one byte Block Check Characters for appending to the end of the
message. The CrcReg variable in C in an unsigned short. After calculating the
values of BCC1? and BCC2?, I use MKBYT$ to convert them to string data.
The first Block Check Character is derived from the final value accumulated in the
CRC Register as follows:
I believe it's equivalent in PowerBASIC is:
The second Block Check Character is calculated like this:
It's equivalent in PowerBASIC should be:
The function that calculates the 1st Block Check Character is called first, and the
function that generates the 2nd is called immeadiately after. In PowerBASIC, the
first function modifies CrcReg??. When the second function calculates BCC2, it uses
a value for CrcReg?? that is now different.
In C, does the value of CrcReg?? in the first function get modified, or does the function
merely return the value of the equation, leaving CrcReg unmodified?
Did I translate the C code correctly into PowerBASIC? Am I missing something else? Any
and all input and help appreciated.
------------------
Mark Pruitt
[email protected]
generates two one byte Block Check Characters for appending to the end of the
message. The CrcReg variable in C in an unsigned short. After calculating the
values of BCC1? and BCC2?, I use MKBYT$ to convert them to string data.
The first Block Check Character is derived from the final value accumulated in the
CRC Register as follows:
Code:
return (~((CrcReg >> 8) & 0x00ff))
Code:
SHIFT RIGHT CrcReg??, 8 BCC1? = NOT(CrcReg?? AND &h00ff)
Code:
return(~(CrcReg & 0x00ff))
Code:
BCC2? = NOT(CrcReg?? AND &h00ff)
function that generates the 2nd is called immeadiately after. In PowerBASIC, the
first function modifies CrcReg??. When the second function calculates BCC2, it uses
a value for CrcReg?? that is now different.
In C, does the value of CrcReg?? in the first function get modified, or does the function
merely return the value of the equation, leaving CrcReg unmodified?
Did I translate the C code correctly into PowerBASIC? Am I missing something else? Any
and all input and help appreciated.
------------------
Mark Pruitt
[email protected]
Comment