I am trying to convert a C/C++ class into a Java equivalent. It's going ok so far but I've got to this bit of code and Java is complaining.
// Isolate each byte in turn
cRecByte = lpszRec[ lRecByteCount++ ] & 0x00FF;
cRecByte is a char
lpszRec is a LPCSTR
lRecByteCount is a long
This works in the C++ code but won't work in Java.
In my Java code I have exactly the same line with the following differences
cRecByte is a char
lpszRec is a String
lRecByteCount is a long
The errors I get (as I'd expect) are
Type mismatch: cannot convert from int to char
Type mismatch: cannot convert from long to int
For some context I'm trying to re-write/emulate a Hash Totaling function that was written in the 1980's that is still used by our legacy systems today. Replacing them with something new would cost a fortune in dev/test costs so I have to continue along this path.
The piece of code I've put up is designed to separate out each character from a given record (line of text).
Any help would greatly appreciated.
Some code as requested - This is from the C++ file. I've only gone as far as where I've got to as the actual class is quite large.
void CHashTotalFile::CalcRecHashTotal( /*[in]*/ LPCSTR lpszRec,
/*[in]*/ DWORD dwRecLen,
/*[in]*/ long lIteration,
/*[in,out]*/ UINT64& u64HashTotal,
SYSTYPE stType ) throw()
{
char cRecByte;
LPCSTR szNullReplacer = "CALCULATE HASH TOTAL";
const static int nLenNullReplacer = lstrlenA( szNullReplacer );
const static char szRandomMap[] = { 17,
5,
37,
31,
53,
19,
41,
7,
11,
2,
23,
3,
29,
47,
43,
13 };
// 64bit unsigned integer data types:
UINT64 u64ByteValue;
UINT64 u64Carry;
// long data types:
long lByteWord; // Used in u64ByteValue & offset to random map
long lRecByteCount; // Byte count within (actual) record - used as subscript to data
long lRecByteIndex; // Byte count within (logical) record - used in hashing calculations
// int data types:
int nAttempts;
int nByteDistance; // 'random' distance which rotates (right) the hash total
int nHashDistance; // 'random distance which rotates (left) the hash total
int nWordValue; // From data - offset to random map for hash distance
bool bGenerated = false;
// No exception calls or error logging here as efficiency is the name of the game!
// (or not so much inefficiency!)
// If text & this is a blank line (i.e. \n) set to record length to zero
if( m_fText && lpszRec[0] == NEWLINE_CHARACTER )
dwRecLen = 0;
// use dummy string where no data
if( dwRecLen == 0 )
{
lpszRec = szNullReplacer;
dwRecLen = nLenNullReplacer;
}
for( nAttempts = 0; (nAttempts <= MAX_HASH_ATTEMPTS) && !bGenerated; nAttempts++ )
{
// Loop around every byte in the record
for( lRecByteCount = lRecByteIndex = 0L; lRecByteCount < dwRecLen; lRecByteIndex++ )
{
// Isolate each byte in turn
cRecByte = lpszRec[ lRecByteCount++ ] & 0x00FF;
if( m_fText ) // If text