How to convert char to hex stored in uint8_t form?

后端 未结 5 1016
星月不相逢
星月不相逢 2021-01-27 05:11

Suppose I have these variables,

const uint8_t ndef_default_msg[33] = {
    0xd1, 0x02, 0x1c, 0x53, 0x70, 0x91, 0x01, 0x09,
    0x54, 0x02, 0x65, 0x6e, 0x4c, 0x69         


        
5条回答
  •  爱一瞬间的悲伤
    2021-01-27 05:29

    If I understand right, you read data of hex format stored in ndef_input, parse it and save the value in ndef_msg.

    you may use

    // parse the hex string and store it in an int variable
    int temp_int;
    sscanf(ndef_input, "%x", &temp_int);
    // covert it to uint8_t type
    ndef_msg = malloc(sizeof(uint8_t));
    *ndef_msg = (uint8_t)temp_int;
    

提交回复
热议问题