can't translate from c++

mizzark49

New member
Joined
Jun 20, 2007
Messages
1
Programming Experience
3-5
Hi everyone. I'm converting over an old program for work that was written in C++. I have 90% completed, but am struggling with a few functions.

Here is what I have in C++:


int ReadPickJc5 ()
{
unsigned long i, j, ulBytes;
char * pPick, g_pByteInputPick;

ulBytes = (g_design.ulInputYarns + 7) / 8;

pPick = (char*)malloc (ulBytes);
if (pPick == NULL)
{
return 1;
}

if ( fread (pPick, 1, ulBytes, inFile) != ulBytes)
{
free (pPick);
return 1;
}


for (i=0; i<ulBytes; i++)
{
for (j=0; j<8; j++)
{

if ((i*8 + j) >= g_design.ulInputYarns) break;
*(g_pByteInputPick + i*8 + j) = BitToByte (*(pPick + i), j);

}
}

free (pPick);

return 0;
}
char BitToByte (char byte, short bitIndex)
{
char reply;
reply = byte >> bitIndex;
reply = reply & 1;
return reply;
}


Here's what I have written in vb.net (2003):

Public Function ReadPickJc5() As Int32

Dim i, j, ulBytes As Long
Dim pPick As ArrayList = New ArrayList
Dim counter As Int32 = 0
Dim tempPickReturned As ArrayList = New ArrayList

ulBytes = (g_design.ulInputYarns + 7) / 8

counter = 0
While (counter < ulBytes)
pPick.Add(bRead.ReadByte())
counter += 1
End While


i = 0
While (i < ulBytes)

j = 0
While (j < 8)

If ((i * 8 + j) >= g_design.ulInputYarns) Then
Exit While
End If

'No idea how to translate this expression:
'tempPickReturned.Item(i * 8 + j) = BitToByte(pPick(i), j)

j += 1
End While
i += 1
End While

End Function

Public Function BitToByte(ByVal thisByte As Byte, ByVal shiftValue As Int _32) As Byte

Dim reply As Byte

reply = Convert.ToByte(thisByte >> shiftValue)
reply = reply And 1
Return reply
End Function


Any help on this would be greatly appreciated. I've spent about 2 days so far hung up on this part. Thanks!
 
Back
Top