在2“ long”上执行XOR操作变量并在.NET Core Console应用程序中显示字母数字结果
我正在构建一个.NET Core Console应用程序,其中我正在尝试在2“长”数据类型值上执行“ XOR”操作。我想要的结果应该是字母数字,例如“ 21341fak234a213kr”,但我会得到整数的结果。
在2个“长”变量上执行XOR操作并显示字母数字结果?
代码
using System.Text;
Console.WriteLine("Please enter your PAN Number: ");
long PAN = long.Parse(Console.ReadLine());
Console.WriteLine("Please enter your PIN Number: ");
long PIN = long.Parse(Console.ReadLine());
long PinBlock()
{
// PAN Code without first 3 characters and last character
string str1 = Convert.ToString(PAN).Remove(0,3);
string str2 = str1.Remove(str1.Length - 1, 1);
// Adding 4 0s at the start of the remaining PAN Number
int count = 4;
char someChar = '0';
string AlgoA = str2.PadLeft(count + str2.Length, someChar);
Console.WriteLine("ALgoA: " + AlgoA);
//Finding the length of the pin code and adding it to the pin code wth 10 'F's
string PinLength = Convert.ToString(PIN);
PinLength = PinLength.ToString();
string result = String.Format("{0,2:X2}", PinLength.Length);
string AlgoB = result + PIN + "FFFFFFFFFF";
Console.WriteLine("ALgoB: " + AlgoB);
byte[] AlgoAbytes = Encoding.ASCII.GetBytes(AlgoA);
long AlgoAlong = BitConverter.ToInt64(AlgoAbytes);
Console.WriteLine("ALgoAlong: " + AlgoAlong);
byte[] AlgoBbytes = Encoding.ASCII.GetBytes(AlgoB);
long AlgoBlong = BitConverter.ToInt64(AlgoBbytes);
Console.WriteLine("ALgoBlong: " + AlgoBlong);
long PinBlock = AlgoAlong ^ AlgoBlong;
return PinBlock;
}
Console.WriteLine("XOR of 2 long Values: " + PinBlock());
I'm building a .NET Core console application in which I'm trying to perform an "XOR" operation on 2 "Long" datatype values. The result I want should be alphanumeric like "21341FAK234A213KR", but I'm getting results as integers.
Perform XOR operation on 2 "Long" variables and display the alphanumeric result?
CODE
using System.Text;
Console.WriteLine("Please enter your PAN Number: ");
long PAN = long.Parse(Console.ReadLine());
Console.WriteLine("Please enter your PIN Number: ");
long PIN = long.Parse(Console.ReadLine());
long PinBlock()
{
// PAN Code without first 3 characters and last character
string str1 = Convert.ToString(PAN).Remove(0,3);
string str2 = str1.Remove(str1.Length - 1, 1);
// Adding 4 0s at the start of the remaining PAN Number
int count = 4;
char someChar = '0';
string AlgoA = str2.PadLeft(count + str2.Length, someChar);
Console.WriteLine("ALgoA: " + AlgoA);
//Finding the length of the pin code and adding it to the pin code wth 10 'F's
string PinLength = Convert.ToString(PIN);
PinLength = PinLength.ToString();
string result = String.Format("{0,2:X2}", PinLength.Length);
string AlgoB = result + PIN + "FFFFFFFFFF";
Console.WriteLine("ALgoB: " + AlgoB);
byte[] AlgoAbytes = Encoding.ASCII.GetBytes(AlgoA);
long AlgoAlong = BitConverter.ToInt64(AlgoAbytes);
Console.WriteLine("ALgoAlong: " + AlgoAlong);
byte[] AlgoBbytes = Encoding.ASCII.GetBytes(AlgoB);
long AlgoBlong = BitConverter.ToInt64(AlgoBbytes);
Console.WriteLine("ALgoBlong: " + AlgoBlong);
long PinBlock = AlgoAlong ^ AlgoBlong;
return PinBlock;
}
Console.WriteLine("XOR of 2 long Values: " + PinBlock());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案。我没有将它们转换为碎片,而是将它们转换为十六进制。这是代码:
I found the answer. Rather than converting them into bits, I converted them into Hexadecimal. Here's the code: