请教ToInt64()和ToInt32()怎么转换?
本人小白新手,刚开始接触c#,在学习中没有经验,遇到不懂的向各位请教。通过cmd命令“wmic CPU get ProcessorID”获得Cpucode=“BFEBFBFF00090675”程序如下:
public static string CalculateSerialNum11938836(string cpucode)
{
string str = cpucode.Substring(cpucode.Length - 6, 3); "从第10为开始数3个数,得到009”不知道这么理解对不对。
string str2 = cpucode.Substring(cpucode.Length - 3, 3); "从第13为开始数3个数,得到067”
string str3 = (Convert.ToInt64(str, 0x10) * Convert.ToInt64(str2, 0x10)).ToString();
string str4 = str3;
while (str3.Length < 6)
{
str3 = "0" + str3;
}
int num2 = (Convert.ToInt32(str4) * 0xb62c14) + 0xb62c14;
return (num2.ToString().Substring(0, 6) + str3.Substring(str3.Length - 6, 6));
}
我知道0xb62c14 是11938836
但是不知道ToInt64()和ToInt32()怎么转换,能讲解下吗
班主能指导下吗 好象表述不够明确啊。你发的源码里Convert.ToInt64(str, 0x10)不是有实例吗? 3yu3 发表于 2022-6-24 21:23
好象表述不够明确啊。你发的源码里Convert.ToInt64(str, 0x10)不是有实例吗?
请教下num2是多少
return什么值? 本帖最后由 3yu3 于 2022-6-24 22:53 编辑
using System;
class Program
{
public static void Main(string[] args)
{
string text = CalculateSerialNum11938836("BFEBFBFF00090675");
Console.WriteLine("最后结果= " + text);
}
public static string CalculateSerialNum11938836(string cpucode)
{
string str = cpucode.Substring(cpucode.Length - 6, 3);
Console.WriteLine("str = " + str);
string str2 = cpucode.Substring(cpucode.Length - 3, 3);
Console.WriteLine("str2 = " + str2);
long str_toInt64 = Convert.ToInt64(str, 0x10);
Console.WriteLine("str_toInt64 = " + str_toInt64);
long str2_toInt64 = Convert.ToInt64(str2, 0x10);
Console.WriteLine("str2_toInt64 = " + str2_toInt64);
string str3 = (str_toInt64 * str2_toInt64).ToString();
Console.WriteLine("str3 = " + str3);
string str4 = str3;
Console.WriteLine("str4 = " + str4);
while (str3.Length < 6)
{
str3 = "0" + str3;
}
Console.WriteLine("str3不足6位前面补0 = " + str3);
int str4_toInt32 = Convert.ToInt32(str4);
Console.WriteLine("str4_toInt32 = " + str4_toInt32);
int num4 = str4_toInt32 * 0xb62c14;
Console.WriteLine("str4_toInt32 * 0xb62c14 = " + num4);
int num2 = (num4) + 0xb62c14;
Console.WriteLine("num2 = " + num2);
return (num2.ToString().Substring(0, 6) + str3.Substring(str3.Length - 6, 6));
}}
https://www.bejson.com/runcode/csharp/
在线运行结果:
标准输出:
str = 090
str2 = 675
str_toInt64 = 144
str2_toInt64 = 1653
str3 = 238032
str4 = 238032
str3不足6位前面补0 = 238032
str4_toInt32 = 238032
str4_toInt32 * 0xb62c14 = -1443339200
num2 = -1431400364
最后结果= -14314238032
3yu3 发表于 2022-6-24 22:12
using System;
class Program
{
谢谢您,我再通过这个在线运行学习下。
页:
[1]