为什么没人理我~~~~~~这可是偶的处女贴啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~
up~~up~~~~~

解决方案 »

  1.   

    自己编程:
    #region About Hex
    public static int HexToInt(string strHex)
    {
    strHex.ToUpper();
    int intValue=0;
    if(strHex.Length>4)
    return 0;
    for(int i=0;i<strHex.Length;i++)
    if(!((strHex[i]>='0'&&strHex[i]<='9')||(strHex[i]>='A'&&strHex[i]<='F')||(strHex[i]>='a'&&strHex[i]<='f')))
    return 0;
    else
    {
    intValue*=16;
    intValue+=BitHexToInt(strHex[i]);
    }
    return intValue;
    }
    public static int BitHexToInt(char chrHex)
    {
    if(!((chrHex>='0'&&chrHex<='9')||(chrHex>='A'&&chrHex<='F')||(chrHex>='a'&&chrHex<='f')))
    return 0;
    if(chrHex>='A'&&chrHex<='F')
    return chrHex-'A'+10;
    if(chrHex>='a'&&chrHex<='f')
    return chrHex-'a'+10;
    return chrHex-'0';
    }
    #endregion
      

  2.   

    自己编程:
    #region About Hex
    public static int HexToInt(string strHex)
    {
    strHex.ToUpper();
    int intValue=0;
    if(strHex.Length>4)
    return 0;
    for(int i=0;i<strHex.Length;i++)
    if(!((strHex[i]>='0'&&strHex[i]<='9')||(strHex[i]>='A'&&strHex[i]<='F')||(strHex[i]>='a'&&strHex[i]<='f')))
    return 0;
    else
    {
    intValue*=16;
    intValue+=BitHexToInt(strHex[i]);
    }
    return intValue;
    }
    public static int BitHexToInt(char chrHex)
    {
    if(!((chrHex>='0'&&chrHex<='9')||(chrHex>='A'&&chrHex<='F')||(chrHex>='a'&&chrHex<='f')))
    return 0;
    if(chrHex>='A'&&chrHex<='F')
    return chrHex-'A'+10;
    if(chrHex>='a'&&chrHex<='f')
    return chrHex-'a'+10;
    return chrHex-'0';
    }
    #endregion
      

  3.   

    谢谢。c#里没有相关的api吗?/
      

  4.   

    感谢您使用微软产品。您可以使用Int32.Parse方法,但是需要有所变动,例子代码如下(以你举的0xB2为例):string hexString = "0xB2";
    string myString = hexString.Substring(2);
    int myInt = Int32.Parse(myString, System.Globalization.NumberStyle.HexNumber | System.Globalization.NumberStyle.AllowHexSpecifier);在Int32.Parse中指明:System.Globalization.NumberStyle.AllowHexSpecifier则将myString作为16进制数处理,但不可包含"0x"前缀,参见MSDN中的说明:
    Indicates that the numeric string can have notation that signifies that the number is hexadecimal. Valid hexadecimal values include the numeric digits 0-9 and the hexadecimal digits A-F and a-f. Hexadecimal values can be left-padded with zeros. Strings parsed using this style are not permitted to be prefixed with "0x".因此在处理时要先取出原String的SubString然后进行类型转换。
    希望能对您有所帮助!======================
    - 微软全球技术中心本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
    ======================