上一篇:给图片添加版权信息(C#) >>
c#中int 转string 16进制和16转double的方法
#region change hex to double
private Double HexConverToDouble(string hexString)
{
if (hexString == "")
{
return 0;
}
string data;
if (hexString.StartsWith("0x"))
{
data = hexString.Substring(2);
}
else
{
data = hexString;
}
char[] eachData = data.ToCharArray();
Double result = 0;
for (int i = 0; i < eachData.Length; i++)
{
char charValue = eachData[i];//eachData[m];
Double x = 16;//如果是八进制则写成8就可以
Double y = System.Convert.ToDouble(eachData.Length - i - 1);
switch (charValue)
{
case @#0@#:
break;
case @#1@#:
result += 1 * Math.Pow(x,y);
break;
case @#2@#:
result += 2 * Math.Pow(x,y);
break;
case @#3@#:
result += 3 * Math.Pow(x,y);
break;
case @#4@#:
result += 4 * Math.Pow(x,y);
break;
case @#5@#:
result += 5 * Math.Pow(x,y);
break;
case @#6@#:
result += 6 * Math.Pow(x,y);
break;
case @#7@#:
result += 7 * Math.Pow(x,y);
break;
case @#8@#:
result += 8 * Math.Pow(x,y);
break;
case @#9@#:
result += 9 * Math.Pow(x,y);
break;
case @#A@#:
result += 10 * Math.Pow(x,y);
break;
case @#B@#:
result += 11 * Math.Pow(x,y);
break;
case @#C@#:
result += 12 * Math.Pow(x,y);
break;
case @#D@#:
result += 13 * Math.Pow(x,y);
break;
case @#E@#:
result += 14 * Math.Pow(x,y);
break;
case @#F@#:
result += 15 * Math.Pow(x,y);
break;
case @#a@#:
result += 10 * Math.Pow(x,y);
break;
case @#b@#:
result += 11 * Math.Pow(x,y);
break;
case @#c@#:
result += 12 * Math.Pow(x,y);
break;
case @#d@#:
result += 13 * Math.Pow(x,y);
break;
case @#e@#:
result += 14 * Math.Pow(x,y);
break;
case @#f@#:
result += 15 * Math.Pow(x,y);
break;
default :
break;
}
}
return result;
}
#region convert the int32 to hex(string) //这个方法通用性不好,只能是int的转string的16进制
private string specInttoString(int source)//被主要方法调用的一个辅助方法
{
if(source <10)
{
return source.ToString();
}
else
{
switch(source)
{
case 10:
return "A";
case 11:
return "B";
case 12:
return "C";
case 13:
return "D";
case 14:
return "E";
case 15:
return "F";
default:
return "";
}
}
}
private string INTtoHEx(int source)//主要方法
{
if(source <10)
{
return "0x" + source.ToString();
}
else if (source <=15)
{
return "0x" + specInttoString(source);
}
else
{
int raiseNum = 16;
int addNum = 16;
int positionNum = 1;
while((source - addNum) >= 0)
{
positionNum++;
addNum = addNum * raiseNum;
}
int[] valuePositionNum = new int[positionNum];
for(int i = 0;i
{
valuePositionNum[i] = 0;
}
int[] valueAddNum = new int[positionNum];
for(int i = 0;i
{
valueAddNum[i] = Convert.ToInt32( Math.Pow(raiseNum,i));
}
int[] decreaseSource = new int[positionNum];
decreaseSource[positionNum -1] = source;
for(int i = positionNum -1;i>=0;i--)
{
while((decreaseSource[i] - valueAddNum[i] ) >=0)
{
if(i != 0)
decreaseSource[i -1] = decreaseSource[i] - valueAddNum[i] ;
valuePositionNum[i]++;
valueAddNum[i]= valueAddNum[i] +Convert.ToInt32( Math.Pow(raiseNum,i));
}
}
string[] stringValuePositionNum = new string[positionNum];
for(int i = 0;i
{
stringValuePositionNum[i] = specInttoString(valuePositionNum[i]);
}
string result = "0x";
for(int i = positionNum -1;i>=0;i--)
{
result = result + stringValuePositionNum[i];
}
return result;
// string[] hexList = new string[positionNum + 1];
// hexList[positionNum] = specInttoString(positionNum);
}
}
#endregion
#endregion
下一篇:C#,结构成员是引用,会发生什么 >>
相关文章:
- · AOP C#在行动
- · Visual C# 2005 Express Edition Beta的第一天使用
- · 基类和子类的调用顺序(C#,java)
- · 哲学家就餐问题的C#实现
- · 走迷宫C#版(二)
- · 走迷宫C#版(一)
- · C#中奇妙的操作符重载
- · C#实现查看文本框(如*号密码框)
- · 关于c#中的消息处理函数和vc中的消息处理函数区别
- · C#操作消息队列
- · Questioning C# (三)
- · Questioning C# (二)
- · Questioning C# (一)
- · 用C#代码动态改变页面样式
- · 用C#去除代码的SourceSafe管理(续篇)
- · 用C#去除代码的SourceSafe管理
- · 探究Singleton设计模式
- · C#中在应用程序和DLL使用消息
- · [c#]:如何在C#中读写INI文件(五)
- · [c#]:如何在C#中读写INI文件(四)
- · [c#]:如何在C#中读写INI文件(三)
- · [c#]:如何在C#中读写INI文件(二)
- · [c#]:如何在C#中读写INI文件(一)
- · 将人民币的数字表示转化成大写表示(C#版)
- · 使用C#拷贝String到struct
- · C#中如何对当前窗体进行打印预览
- · 设计模式c#语言描述——合成(Composite)模式
- · An Intro to Constructors in C#
- · 巧用头脑思考,提高软件运行效率-浅谈程序算法
- · MapX 控件在C# 中的应用
- · 设计模式c#语言描述——适配器模式
- · 设计模式c#语言描述——建造者模式
- · 中英文语音合成与中文语音识别技术在c#中的应用(二)
- · 中英文语音合成与中文语音识别技术在c#中的应用(一)
- · 通过C#实现集合类纵览.NET Collections及相关技术
- · c#中的反射
- · 在C#中操作XML
- · C#—非对称加密:加密文件
