<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div dir="ltr" id="yui_3_16_0_1_1434960628479_5352">I have a situation where I need to convert a value that is stored as 3 bytes to a char.</div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353">The can be for example 7ED95, which is reported in 3 consequtive bytes 07, ED, 95.</div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353">This value in decimal is 519573, which corresponds to a 51.9% SOC. </div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353">Is the proper way to do this conversion (from the 3 bytes to the value of 51) like this:</div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353"><br></div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353">char soc = (char)(((unsigned long)value[1]<<16 + (unsigned long)value[2]<<16 + (unsigned long)value[3])/10000);</div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353"><br></div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353">I have been doing stuff like that before with unions, but can't remember how either.</div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353"><br></div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353">Thanks,</div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353"><br></div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353">Nikolay</div><div dir="ltr" id="yui_3_16_0_1_1434960628479_5353" class="" style=""> </div></div></body></html>