//
如"我"字的gb2312编码: 十六进制表示为 ce,十进制表示为206.
//
它的演算为: int b=206(11001110)(ce); b>>4=12(1100)(c); b & 0xF (11001110 & 00001111)=14(00001110)(e);
Byte[] buffer
=
null
;
buffer
=
System.Text.Encoding.GetEncoding(
"
GB2312
"
).GetBytes(ChinaStr1);
string
str2
=
ToHexString(buffer) ;
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
static
char
[] hexDigits
=
{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
;
private
static
string
ToHexString(
byte
[] bytes)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
char[] chars = new char[bytes.Length * 4];
for (int i = 0; i < bytes.Length; i++)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int b = bytes[i];
chars[i * 4 ]='\\';
chars[i * 4 + 1]='\'';
chars[i * 4 + 2] = hexDigits[b >> 4];
chars[i * 4 + 3] = hexDigits[b & 0xF];
}
return new string(chars);
}
转载于:https://www.cnblogs.com/furenjun/archive/2006/02/07/326500.html