Convert array of char[] to byte[] and vice versa? C++

前端 未结 4 844
谎友^
谎友^ 2020-12-31 07:12

What is the best way to convert an array of chars to bytes and vice versa?

Solution:

void CharToByte(char* chars, byte* bytes, unsigned int count){
          


        
4条回答
  •  天涯浪人
    2020-12-31 07:24

    There is no byte type in C++. You could typedef 'unsigned char' to 'byte' if that makes it nicer. Really thats all a byte is in C++ - an unsigned char. Aside from that, yes I would cast... but this cast is better:

    unsigned_char_arr[i]= static_cast(char_arr[i]);
    

    or... just use the char array and cast it when it needs to be interpreted as an unsigned char...

提交回复
热议问题