gpt4 book ai didi

c++ 到 vb.net,情侣对话问题

转载 作者:行者123 更新时间:2023-11-28 08:02:35 24 4
gpt4 key购买 nike

好的,这是我有点迷惑的函数(生锈的按位运算符)

void two_one(unsigned char *in,int in_len,unsigned char *out)
{
unsigned char tmpc;
int i;

for(i=0;i<in_len;i+=2){
tmpc=in[i];
tmpc=toupper(tmpc);
if((tmpc<'0'||tmpc>'9') && (tmpc<'A'||tmpc>'F'))tmpc='F';
if(tmpc>'9')
tmpc=toupper(tmpc)-'A'+0x0A;
else
tmpc-='0';
tmpc<<=4; //Confused here
out[i/2]=tmpc;

tmpc=in[i+1];
tmpc=toupper(tmpc);
if((tmpc<'0'||tmpc>'9') && (tmpc<'A'||tmpc>'F'))tmpc='F';
if(tmpc>'9')
tmpc=toupper(tmpc)-'A'+0x0A;
else
tmpc-='0';

out[i/2]|=tmpc; //Confused Here
}
}

我把不太明白的两个地方都标出来了。如果有人可以帮助我将这些片段转换为 Vb.Net,或者至少帮助我理解那里发生了什么,那就太棒了。

谢谢。

更新

这就是我想出的,但它并没有给我返回正确的数据...这里有什么问题吗?

Public Function TwoOne(ByVal inp As String) As String
Dim temp As New StringBuilder()
Dim tempc As Char
Dim tempi As Byte
Dim i As Integer
Dim len = inp.Length
inp = inp + Chr(0)
For i = 0 To len Step 2
If (i = len) Then Exit For
tempc = Char.ToUpper(inp(i))
If ((tempc < "0"c Or tempc > "9"c) AndAlso (tempc < "A"c Or tempc > "F"c)) Then
tempc = "F"c
End If
If (tempc > "9"c) Then
tempc = Char.ToUpper(tempc)
tempc = Chr(Asc(tempc) - Asc("A"c) + &HA)
Else
tempc = Chr(Asc(tempc) - Asc("0"c))
End If
tempc = Chr(CByte(Val(tempc)) << 4)
Dim tempcA = tempc

tempc = Char.ToUpper(inp(i + 1))
If ((tempc < "0"c Or tempc > "9"c) AndAlso (tempc < "A"c Or tempc > "F"c)) Then
tempc = "F"c
End If
If (tempc > "9"c) Then
tempc = Char.ToUpper(tempc)
tempc = Chr(Asc(tempc) - Asc("A"c) + &HA)
Else
tempc = Chr(Asc(tempc) - Asc("0"c))
End If
temp.Append(Chr(Asc(tempcA) Or Asc(tempc)))
Next
TwoOne = temp.ToString()
End Function

最佳答案

tmpc <<= 4移动 tmpc 中的位向左 4 位,然后将值赋回给 tmpc。因此如果tmpc00001101 , 它变成了 11010000

out[i/2]|=tmpc按位或数组值与 tmpc .因此如果out[i/2]01001001tmpc10011010 , 然后 out[i/2]变成 11011011

编辑(更新问题):线条 tmpc-='0';原始代码与您的新代码不完全相同 tempc = "0"c . -=从变量中减去值,因此你需要 tempc = tempc - "0"c或类似的

关于c++ 到 vb.net,情侣对话问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11043191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com