【问题标题】:Convert GetBytes C# line to VB.Net将 GetBytes C# 行转换为 VB.Net
【发布时间】:2012-09-17 18:11:13
【问题描述】:

我有一行用 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);

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

谢谢

【问题讨论】:

标签: c# .net vb.net


【解决方案1】:

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

comp.Write(BitConverter.GetBytes(CUShort(Not length)), 0, 2)

【讨论】:

    【解决方案2】:

    你可以试试这段代码

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      相关资源
      最近更新 更多