将1 BYTE转换为int值,从00..FF转换为0..255

时间:2012-03-22 20:23:24

标签: embedded int byte

在MPLAB C中将BYTE(00 - FF)转换为int(0 - 255)值 我试过这个,但它不起作用,因为我想要它:

 atoi(i)

(i - '0')

1 个答案:

答案 0 :(得分:2)

你可以这样做

unsigned char c = 0xF3; //there is no byte in C but unsigned char is basically equivalent
int i = c & 0xFFFF; //this will set i to the value of c;

输出

i = 243; //the decimal version of 0xF3.
相关问题