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

发布时间 2023-04-07 15:35:46作者: qq921201008
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 ;
}