Reputation: 637
I am receiving a hex value
uint8_t length = rx_dataframe.dlc// Current value of this in hex is 0x08
I am trying to get a char value("8") from this value. As per the ASCII table hex value of "8" is 0x38. I have tried directly adding "0" but being confused in this
tx_buff_dlc[0]= (rx_dataframe.dlc)+"0";// I know its not currect but just thought
tx_buff_dlc[0]=0x08+0x30
will be equal to 0x038
and will get "8"
Can someone please explain how are the addition for the hex value done in C
Upvotes: 0
Views: 644
Reputation: 11706
"0"
denotes a string, which has a particular address. The addition will give you some random location in memory, which is not what you want.
Instead, use single quotes: '0'
. This will compile to whatever the value is for the character '0'
(for ASCII, it's 0x30 as you mentioned). Then, the addition will work as intended.
Upvotes: 9