怎么样将3转换为33? 1. 你可以用convert.toint32先转换成一个整数,2. 把10进制转换成16进制 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我也晕了是从串口取出来的,按照说明是ASCII码字符,想把它变为十六进制表示. 给你个例子using System;class HexTest{ static char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; public static string ToHexString(byte[] bytes) { char[] chars = new char[bytes.Length * 2]; for (int i = 0; i < bytes.Length; i++) { int b = bytes[i]; chars[i * 2] = hexDigits[b >> 4]; chars[i * 2 + 1] = hexDigits[b & 0xF]; } return new string(chars); } static void Main() { byte[] b = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF}; string s = "234A"; Console.WriteLine(ToHexString(System.Text.Encoding.ASCII.GetBytes(s))); Console.ReadLine(); }} 关于C#的问题,我是新手,求高手解答,谢谢。 c#结构体指针的问题 [紧急求助]c# winform程序 RDLC报表问题!!! 在线等待~~~~~~~~~~~~~ md5码难道还有不同吗? 编码问题 怎么取消 键盘按键 的延迟 关于在C#中使用一个C++中的结构问题,谢谢 datagrid 的 ButtonColumn 问题? 如何在aspx 页面 向自身页面提交内容 主从表关联问题 请教在winform中 MDI应程序中 单件调用窗件类应该怎么写呢? 如何在WebForm中实现象WinForm中的OpenFileDialog的功能?
using System;class HexTest
{
static char[] hexDigits = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
public static string ToHexString(byte[] bytes)
{
char[] chars = new char[bytes.Length * 2];
for (int i = 0; i < bytes.Length; i++)
{
int b = bytes[i];
chars[i * 2] = hexDigits[b >> 4];
chars[i * 2 + 1] = hexDigits[b & 0xF];
}
return new string(chars);
}
static void Main()
{ byte[] b = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF};
string s = "234A";
Console.WriteLine(ToHexString(System.Text.Encoding.ASCII.GetBytes(s)));
Console.ReadLine();
}
}