Convert char* to uint8_t

后端 未结 4 722
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 02:30

I transfer message trough a CAN protocol.

To do so, the CAN message needs data of uint8_t type. So I need to convert my char* to ui

4条回答
  •  一生所求
    2020-12-18 02:45

    uint8_t is 8 bits of memory, and can store values from 0 to 255

    char is probably 8 bits of memory

    char * is probably 32 or 64 bits of memory containing the address of a different place in memory in which there is a char

    First, make sure you don't try to put the memory address (the char *) into the uint8 - put what it points to in:

    char from;
    char * pfrom = &from;
    uint8_t to;
    to = *pfrom;
    

    Then work out what you are really trying to do ... because this isn't quite making sense. For example, a float is probably 32 or 64 bits of memory. If you think there is a float somewhere in your char * data you have a lot of explaining to do before we can help :/

提交回复
热议问题