[Ovmsdev] 3 bytes to char
Nikolay Shishkov
nshishkov at yahoo.com
Mon Jun 22 16:30:51 HKT 2015
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20150622/d4187115/attachment.htm>
More information about the OvmsDev
mailing list