22 Jun
2015
22 Jun
'15
4:30 p.m.
I have a situation where I need to convert a value that is stored as 3 bytes to a char.The can be for example 7ED95, which is reported in 3 consequtive bytes 07, ED, 95.This value in decimal is 519573, which corresponds to a 51.9% SOC. Is the proper way to do this conversion (from the 3 bytes to the value of 51) like this: char soc = (char)(((unsigned long)value[1]<<16 + (unsigned long)value[2]<<16 + (unsigned long)value[3])/10000); I have been doing stuff like that before with unions, but can't remember how either. Thanks, Nikolay