
Originally Posted by
retepsnikrep
I'm a real PbPro Maths dunce ...
Baiscally i have a byte array of hex data BD[11] recieved via a serial interface. I'm happy with this and the data recd.
Now taking bytes from array BD [4] and BD [5] as an example i need to perform the following calcu
lation on the bytes.
I appreciate the decimal point will cause an issue. Any examples of code that would perform this.
I came up with
Code:
Result = (((BD[4] * 128) + BD[5]) - 2048) / 20.48
But this losses the accuracy of the end part of the formula?
...
Also for a second formula involving BD [2] & BD [3] I need to
I'm stuck on extracting a value for the right hand digit of the hex number?
Hi,
1) Result = (((BD[4] * 128) + BD[5]) - 2048) / 20.48
lets write it ...
20.48 = 512 /25 ... ; 2048 = 100 * 20.48 ...
result = ((((BD[4] << 7) + BD[5] ) * 25) >> 9) - 100
not so good as a calculation ... don't you have a better formula ???
( BTW... I'm curious to see your project ...) 
BD[5] obviously is a word ( or smaller !!! ) ... so, at least, its 4 lower digits are lost in the calculation ... 
2) It's a typical "masking" job ... ( I suppose it's a HEX digit, you look for ? ) ...
so, you could use ...
Ldigit = Res & $000F( for a Word )
Ldigit = Res & $0000000F ( for a LONG )
Alain
Last edited by Acetronics2; - 6th July 2010 at 11:17.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Bookmarks