今天要說明的是,在C語言中,2個byte如果要轉十進制 如何做?

2個byte分別為high byte 和 low byte,可以組合成一個0-65535大小的十進制 ,

在C語言可以這樣寫:

uint8_t Highbyte; //char high byte
uint8_t Lowbyte;  // char low byte
uint32_t CountValue=0x00;
uint32_t RPMValue=0x00;

CountValue =
(Highbyte/128)*32768 +
(Highbyte%128/64)*16384 +
(Highbyte%128%64/32)*8192 +
(Highbyte%128%64%32/16)*4096+
(Highbyte%128%64%32%16/8)*2048 +
(Highbyte%128%64%32%16%8/4)*1024 +
(Highbyte%128%64%32%16%8%4/2)*512 +
(Highbyte%128%64%32%16%8%4%2/1)*256+
(Lowbyte/128)*128 + 
(Lowbyte%128/64)*64+ 
(Lowbyte%128%64/32)*32 + 
(Lowbyte%128%64%32/16)*16 + 
(Lowbyte%128%64%32%16/8)*8 + 
(Lowbyte%128%64%32%16%8/4)*4 + 
(Lowbyte%128%64%32%16%8%4/2)*2 + 
(Lowbyte%128%64%32%16%8%4%2/1)*1;

arrow
arrow
    文章標籤
    2 bytes to decimal
    全站熱搜
    創作者介紹
    創作者 JL8051 的頭像
    JL8051

    不會的就放這邊

    JL8051 發表在 痞客邦 留言(0) 人氣()