473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Translate from C/C++ to VB

I'm not C/C++ expert and I've been struggling with converting this
piece of code to VB. I would appreciate any help. Thanks.

/*
* uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)
*
* ARGUMENTS
* size_t count :Number of bytes in the buffer
* uint16 crc : Preload value of the CRC
* void *buffer : Buffer whose CRC is to be calculated
*
* DESCRIPTION
* This routine is called to calculate the CCITT CRC value of a block
of data.
* RETURNS
* CRC value.
*/

uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)
{
const uint8 *pBuf = (const uint8*)buffer;

while (count--)
crc = (uint16)((crc >> 8) ^ crcTable[(uint8)(crc ^ *pBuf++)]);
return (crc ^ ((uint16)0xFFFF));
}

May 22 '06 #1
6 2485
ko******@hotmail.com wrote:
I'm not C/C++ expert and I've been struggling with converting this
piece of code to VB. I would appreciate any help. Thanks.

/*[...]


Please ask in a Visual Basic newsgroup (any of microsoft.public.vb.*)

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 22 '06 #2
On Mon, 22 May 2006 10:06:56 -0400, I waved a wand and this message
magically appeared from Victor Bazarov:
I'm not C/C++ expert and I've been struggling with converting this
piece of code to VB. I would appreciate any help. Thanks.

/*[...]


Please ask in a Visual Basic newsgroup (any of microsoft.public.vb.*)


Quite right, what he's trying to do is to "dumb down" C++ code. How dare
he!
--
http://www.munted.org.uk

Take a nap, it saves lives.
May 22 '06 #3
* ko******@hotmail.com:
I'm not C/C++ expert and I've been struggling with converting this
piece of code to VB. I would appreciate any help. Thanks.

/*
* uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)
*
* ARGUMENTS
* size_t count :Number of bytes in the buffer
* uint16 crc : Preload value of the CRC
* void *buffer : Buffer whose CRC is to be calculated
*
* DESCRIPTION
* This routine is called to calculate the CCITT CRC value of a block
of data.
* RETURNS
* CRC value.
*/
First, know that the 'void*' means that this is really bad code, if the
argument order etc. hadn't already told as much.

uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)
'count' is an integer of the largest size you have in VB.

'crc' is a 16-bit integer.

'buffer' is an array of bytes.

{
const uint8 *pBuf = (const uint8*)buffer;

while (count--)
'count--' means

temp = count;
count = count - 1;
"the value of temp as result"

When the expression produces 0 as result it's regarded as False,
otherwise it's regarded as True.

crc = (uint16)((crc >> 8) ^ crcTable[(uint8)(crc ^ *pBuf++)]);
'>>' is a bitlevel right shift, here 8 bits; same as dividing by 256.

'^' is logical Xor.

'crcTable[...]' is, as you probably already think, array indexing.

'*pBuf++' is analogous to

temp = buffer[bufferIndex];
bufferIndex = bufferIndex + 1;
"the value of temp"

with 'bufferIndex' playing the role of 'pBuf'.

return (crc ^ ((uint16)0xFFFF));
}


'0xFFFF' is an integer value expressed in hexadecimal notation.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 22 '06 #4
Alf P. Steinbach wrote:
* ko******@hotmail.com:
I'm not C/C++ expert and I've been struggling with converting this
piece of code to VB. I would appreciate any help. Thanks.

/*
* uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)
*
* ARGUMENTS
* size_t count :Number of bytes in the buffer
* uint16 crc : Preload value of the CRC
* void *buffer : Buffer whose CRC is to be calculated
*
* DESCRIPTION
* This routine is called to calculate the CCITT CRC value of a block
of data.
* RETURNS
* CRC value.
*/


First, know that the 'void*' means that this is really bad code, if the
argument order etc. hadn't already told as much.


I assume you mean that it should be 'const void *'. Otherwise how would
you pass a generic block of memory to a CRC routine?
May 22 '06 #5
Problem solved. I can post the solution if there is anybody interested.
I never had any problems with understanding the function I posted.
However, I don't know VB very well and I was hoping there might be
somebody
who is familiar with both VB and C/C++ and would like to help me
translating
the function.

Thanks everybody for your input.

Alf P. Steinbach wrote:
* ko******@hotmail.com:
I'm not C/C++ expert and I've been struggling with converting this
piece of code to VB. I would appreciate any help. Thanks.

/*
* uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)
*
* ARGUMENTS
* size_t count :Number of bytes in the buffer
* uint16 crc : Preload value of the CRC
* void *buffer : Buffer whose CRC is to be calculated
*
* DESCRIPTION
* This routine is called to calculate the CCITT CRC value of a block
of data.
* RETURNS
* CRC value.
*/


First, know that the 'void*' means that this is really bad code, if the
argument order etc. hadn't already told as much.

uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)


'count' is an integer of the largest size you have in VB.

'crc' is a 16-bit integer.

'buffer' is an array of bytes.

{
const uint8 *pBuf = (const uint8*)buffer;

while (count--)


'count--' means

temp = count;
count = count - 1;
"the value of temp as result"

When the expression produces 0 as result it's regarded as False,
otherwise it's regarded as True.

crc = (uint16)((crc >> 8) ^ crcTable[(uint8)(crc ^ *pBuf++)]);


'>>' is a bitlevel right shift, here 8 bits; same as dividing by 256.

'^' is logical Xor.

'crcTable[...]' is, as you probably already think, array indexing.

'*pBuf++' is analogous to

temp = buffer[bufferIndex];
bufferIndex = bufferIndex + 1;
"the value of temp"

with 'bufferIndex' playing the role of 'pBuf'.

return (crc ^ ((uint16)0xFFFF));
}


'0xFFFF' is an integer value expressed in hexadecimal notation.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


May 22 '06 #6
* ko******@hotmail.com:
[all wrong]


Don't top-post.

Don't quote signatures.

Don't post VB problems in this group.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
1
by: shank | last post by:
I'm sure this is a stretch, but is there some kind of component that I could install to translate from English to Spanish on the fly? I have a lot of equipment features and specifications that I...
4
by: Gadrin77 | last post by:
I have data that looks like <Root> <Main Value="Line1|Line2.|Line3|Line4.|Line5"/> </Root> I'm using Translate(@Value, "|.", ",")
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
6
by: Anders K. Olsen | last post by:
Hello group I'm trying to list the users and groups who has read access to a file. I use .NET 2.0 and FileInfo.GetAccessControl().GetAccessRules(...) and then loop through the...
1
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
9
bvdet
by: bvdet | last post by:
I have done some more work on a simple class I wrote to calculate a global coordinate in 3D given a local coordinate: ## Basis3D.py Version 1.02 (module macrolib.Basis3D) ## Copyright (c) 2006...
1
by: =?Utf-8?B?R2F1cmF2?= | last post by:
Hi, I am using the Translate() function in one of the .XSLT file to remove the spaces, like this: <xsl:for-each select=".//Illustration"> <xsl:value-of select="translate(./@illusName, ' ',...
3
by: Kenneth McDonald | last post by:
I have the need to occasionally translate a single word programatically. Would anyone have a Python script that would let me do this using Google (or another) translation service? Thanks, Ken
4
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.