C#十六进制计算器帮助。 [英] C# hex calculator help.

查看:145
本文介绍了C#十六进制计算器帮助。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友你好。我需要一个六角计算器。我做不到。你的建议是什么?我想要的是这样的;



例如;



Hello friends. I need a hex calculator. I could not do. What is your suggestion. What I want is exactly like this ;

for example;

Hexdata = "2020202020442042497c31323334414243353637387c";





计算;



20 + 20 + 20 + 20 + 20 + 44 + 20 + 42 + 49 + 7c + 31 + 32 + 33 + 34 + 41 + 42 + 43 + 35 + 36 + 37 + 38 + 7c = 4f1





calculation;

20+20+20+20+20+44+20+42+49+7c+31+32+33+34+41+42+43+35+36+37+38+7c = 4f1

result= "4f1";







private void HexCalc(string data) 
{

 //Code Here.....

}





感谢您的帮助。我为糟糕的英语和叙述道歉。



我尝试了什么:





Thanks for your help. I apologize for the bad english and the narration.

What I have tried:

string hex;
string result;
int count;

 private void button2_Click(object sender, EventArgs e)
        {
            string data = dataBox.Text;
            string hexdata = ConvertToHex(data);

            for (var i = 0; i< hexdata.Length; i+= 2)
            {
                hex = hexdata.Substring(i, 2);
                count += 2;
                result = Convert.ToString(toplam + hexdata.Substring(count,2));
                if(i == hexdata.Length)
                {
                    textBox7.Text = Convert.ToString(result);
                    return;
                }
               
            }
        }

推荐答案

嗯,你没有显示我们你的ConvertToHex方法,所以我假设那是你出错的地方。



Well, you didn't show us your ConvertToHex method, so I'm assuming that's where you went wrong.

public static byte[] StringToByteArray(string text) 
{
    return Enumerable.Range(0, text.Length)
                     .Where(x => x % 2 == 0)
                     .Select(x => Convert.ToByte(text.Substring(x, 2), 16))
                     .ToArray();
}





此外,我只是为数学部分做这个:





Further, I would simply do this for the math part:

string text = "2020202020442042497c31323334414243353637387c";
int total = this.StringToByteArray(text).Sum(x=>x);
string totalStr = string.Format("{0:x}", total);


这篇关于C#十六进制计算器帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆