How to convert char to hex stored in uint8_t form?

后端 未结 5 1077
星月不相逢
星月不相逢 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:16

    Maybe not very elegant but simple: define a look up table that maps a character code (0 to 255) into a desired value.

    // something like this:
    for( i = 0; i < INPUT_LEN; ++i ) {
        value_in = input[i];
        value_out = lut[value_in];
        array_out[i] = value_out;
    }
    

    I used such not-elegant solutions a couple of times (e.g. for color mapping) and it worked equally good as other fancy solutions

提交回复
热议问题