Translate from C/C++ to VB

K

koobelek

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));
}
 
V

Vladimir Oka

I'm not C/C++ expert and I've been struggling with converting this

There's no language called C/C++. What you have below does look like C
though.
piece of code to VB. I would appreciate any help. Thanks.

If you need VB code, why not post in VB group. Why do you expect that
people in c.l.c will be familiar with it?
/*
* 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)

What's a `unit16`. Presumably `unsigned int` which the author believes
is 16 bits wide, but still.
{
const uint8 *pBuf = (const uint8*)buffer;

Same for `uint8`.
while (count--)
crc = (uint16)((crc >> 8) ^ crcTable[(uint8)(crc ^ *pBuf++)]);

Indentation style leaves a lot to be desired.

This shifts `crc` 8 bits to the right, XORs it with the element of
`crcTable[]` array, indexed by `crc` XORed with whatever `pBuf` points
to, incrementing `pBuf` pointer *afterwards*. Once this is calculated
it is assigned back to `crc`.

Above is repeated until `count` reaches zero.
return (crc ^ ((uint16)0xFFFF));

The function returns `crc` XORed with all-bits-one 16 bit value.

There you go. I've explained what the above does. Now, all you need is
to express that in VB.
 
P

pete

Vladimir said:
There's no language called C/C++. What you have below does look like C
though.


If you need VB code, why not post in VB group. Why do you expect that
people in c.l.c will be familiar with it?

Then again, there's no reason to assume that
anyone on a VB group would know C.

Hmmm ...
 
V

Vladimir Oka

pete said:
Then again, there's no reason to assume that
anyone on a VB group would know C.

Hmmm ...

Yes, it did occur to me as well. That's, more or less, the reason why I
provided "translation" which OP can pass to a VB group and have them
help him out in putting it in VBesse.
 
P

pete

Vladimir said:
Yes, it did occur to me as well.
That's, more or less, the reason why I
provided "translation" which OP can pass to a VB group and have them
help him out in putting it in VBesse.

I hadn't quite realized that.
That was good.
 
R

Roberto Waltman

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.
*/

Computing "the CCITT CRC value of a block of data" is a very common,
frequently needed operation. I am sure you can find ready-to-use VB
code that implements it.
 
K

Keith Thompson

Vladimir Oka said:
(e-mail address removed) wrote: [...]
uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)

What's a `unit16`. Presumably `unsigned int` which the author believes
is 16 bits wide, but still.

Typo: you mean "uint16", not "unit16".
Same for `uint8`.

Both uint8 and uint16 are (optionally) defined in C99's <stdint.h>,
and can easily be defined under C90.
 
V

Vladimir Oka

Keith Thompson opined:
Vladimir Oka said:
(e-mail address removed) wrote: [...]
uint16 calcBlockCRC(size_t count, uint16 crc, void *buffer)

What's a `unit16`. Presumably `unsigned int` which the author
believes is 16 bits wide, but still.

Typo: you mean "uint16", not "unit16".
Indeed.
Same for `uint8`.

Both uint8 and uint16 are (optionally) defined in C99's <stdint.h>,
and can easily be defined under C90.

ITYM uintN_t variety (uint8_t, uint16_t).

--
I have never understood the female capacity to avoid a direct answer to
any question.
-- Spock, "This Side of Paradise", stardate 3417.3

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
 
K

Keith Thompson

Vladimir Oka said:
Keith Thompson opined: [...]
Both uint8 and uint16 are (optionally) defined in C99's <stdint.h>,
and can easily be defined under C90.

ITYM uintN_t variety (uint8_t, uint16_t).

ARGH!

You're right, of course.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top