4

我有一行用 C# 编写的代码,需要转换为 Vb.Net。

在 C# 中

我有这个块...

// Calculate number of 64K blocks
  uint          rowsPerBlock = _MAXBLOCK/widthLength;
  uint          blockSize = rowsPerBlock*widthLength;
  uint          blockCount;
  ushort        length;
  uint          remainder=dcSize;

后来长度变量被赋值并用于其他计算

length = (ushort)((remainder < blockSize) ? remainder : blockSize);

    if (length == remainder)
    {
      comp.WriteByte(0x01);
    }
    else
    {
      comp.WriteByte(0x00);
    }

    comp.Write(BitConverter.GetBytes(length), 0, 2);

    // Write one's compliment of LEN

以上所有内容我都已转换,但以下行除外。

comp.Write(BitConverter.GetBytes((ushort)~length), 0, 2);

这条线的正确转换是什么?

谢谢

4

2 回答 2

5

这将Not在 VB.Net 中用于执行按位求反:

comp.Write(BitConverter.GetBytes(CUShort(Not length)), 0, 2)
于 2012-09-17T18:14:59.333 回答
1

您可以尝试使用此代码

Dim byteArray As Byte( ) = BitConverter.GetBytes( (CUShort)Not length)
comp.Write(byteArray , 0, 2);

链接 BitConverter.GetBytes:http: //msdn.microsoft.com/fr-fr/library/vstudio/fk3sts66.aspx#Y0

链接不:http: //msdn.microsoft.com/fr-fr/library/2cwcswt4%28v=vs.80%29.aspx

于 2012-09-17T18:15:17.410 回答