StringToByte(char* source, uint8_t* dest, int sourceLen)

void StringToByte(char* source, uint8_t* dest, int sourceLen)
{
    int i;
    uint8_t highByte, lowByte;

    for (i = 0; i < sourceLen; i += 2)
    {
        highByte = toupper(source[i]);
        lowByte  = toupper(source[i + 1]);

        if (highByte > 0x39)
            highByte -= 0x37;
        else
            highByte -= 0x30;

        if (lowByte > 0x39)
            lowByte -= 0x37;
        else
            lowByte -= 0x30;

        dest[i / 2] = (highByte << 4) | lowByte;
    }
    return ;
}

 

posted @ 2023-04-07 15:33  qq921201008  阅读(12)  评论(0编辑  收藏  举报