Cadena hexadecimal de C ++ a función de matriz hexadecimal

@ TOC C ++ 16 进制 字符串 转 16 进制 数组 函数
unsigned char buf [], int len)
{ if (str! = NULL && buf! = NULL && len! = NULL) { int Length = sizeof (str); if (Longitud% 2 == 0) { int i = 0; int n = 0; while (* str! = 0 && (n = ((i ++) >> 1)) <len) { buf [n] << = 4; if (* str> = '0' && * str <= '9') { buf [n] | = * str - '0'; } más si (* str> = 'a' && * str <= 'f') { buf [n] | = * str - 'a' + 10; } más si (* str> = 'A' && * str <= 'F') { buf [n] | = * str - 'A' + 10; } str ++; } len = n; } } }



















int main ()
{

char str[] = "453456ABCDFF";
unsigned char ret[6];
StrToHex(str, ret, 6);
for (int i = 0; i < 6; i++)
    {
        printf("%02X", ret[i]);
        printf("\n");
    }

return 0;
}
Inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/hs977986979/article/details/92408162
Recomendado
Clasificación