两个字符型转为一个整型

#include <stdio.h>
#include <stdlib.h>

int main()
{

        unsigned int cmd = 0xffcb;
        unsigned char buf[2] = {0};
        unsigned int tmp;
        buf[0] = cmd >>8;
        buf[1] = cmd;
        printf("%02X %02X \n",buf[0], buf[1]);                                                       
        tmp  = (buf[0] << 8) + buf[1];
        printf("%d \n",tmp);


        return 0;
}

运行结果:

root@ubuntu:/home/# ./test
FF CB 
65483 
root@ubuntu:/home/# 

猜你喜欢

转载自blog.csdn.net/weixin_38184741/article/details/83828682