Convert int (32 bits) to char (8 bits)
问题 I have these definitions: int data = uartBaseAddress[UART_DATA_REGISTER / 4]; // data coming from UART RX port char message[20]; // array of 20 chars Now when I try to do this: message[0] = (char) data; printf("%x", message[0]); It prints (for example): "ffffff9c" . Of course I want only the last 8 bits ("9c") and I don't understand how to properly do the conversion from int to char . EDIT: I mean: i have to populate the array like this: data = 0xFFFFFF9c; message[0] = data & 0xFF; -- it has