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

后端 未结 6 1894
我寻月下人不归
我寻月下人不归 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:12

    CP1 = (unsigned char)(CurrentPosition & 0xFF);
    CurrentPosition >>= 8;
    CP2 = (unsigned char)(CurrentPosition & 0xFF);
    ...
    

提交回复
热议问题