How do I split up a long value (32 bits) into four char variables (8bits) using C?

后端 未结 6 1892
我寻月下人不归
我寻月下人不归 2020-12-29 11:04

I have a 32 bit long variable, CurrentPosition, that I want to split up into 4, 8bit characters. How would I do that most efficiently in C? I am working with an 8bit MCU, 80

6条回答
  •  天涯浪人
    2020-12-29 11:22

    unsigned char *CP = &CurrentPosition;
    

    Now CPn per your original code is accessed via CP[n].

提交回复
热议问题