Torque

Forums

Forums

Guest  

Show or hide header
Welcome Guest, posting in this forum require registration.




Torque » Torque OBD ECU Scanner » Torque Discussion / Ideas » How to handle signed HEX values

Pages: [1]
Author Topic: How to handle signed HEX values
Stratos4C
Member
Posts: 16
Post How to handle signed HEX values
on: January 27, 2018 (GMT)

For some PID’s the result should be a negative value. for example ignition timing. The response shows values like FC80 which should be -7.0 degrees. The complete equation is (256*A+B)/128. But how can I get to show -7 instead of 505 ?

Capp777
Member
Posts: 2993
Post Re: How to handle signed HEX values
on: January 27, 2018 (GMT)

Try this equation:

((Signed(A)*256)+B)*(1/128)

Using your FC 80 hex response…

((Signed(252)*256)+128)*(1/128)

((-4*256)+128)*(1/128)

(-1024+128)*(1/128)

-896*(1/128)

-7

For 8-bit Signed(A) results…

0xFF = -1
0xFE = -2
0xFD = -3
0xFC = -4
.
.
.
0x80 = -128

0x7F = 127
0x7E = 126
0x7D = 125
0x7C = 124
.
.
.
0x00 = 0

Stated another way…

0000 0100 (0x04) FOR +4
1111 1111 (0xFF)
==== ==== XOR FOR ONE’S COMPLIMENT
1111 1011 (0xFB)
0000 0001 (0x01)
==== ==== +1 FOR TWO’S COMPLIMENT
1111 1100 (0xFC) FOR -4

XOR:

…| 0 | 1 |
…………….
0 | 0 | 1 |
…………….
1 | 1 | 0 |
…………….

Stratos4C
Member
Posts: 16
Post Re: How to handle signed HEX values
on: January 30, 2018 (GMT)

Yes! The “Signed” method is working perfectly. Thank you very much!

Is there maybe a list of other terms which can be used for the equations ?

Capp777
Member
Posts: 2993
Post Re: How to handle signed HEX values
on: January 30, 2018 (GMT)

Buried within Wiki links above…

https://torque-bhp.com/wiki/Equations

Stratos4C
Member
Posts: 16
Post Re: How to handle signed HEX values
on: January 31, 2018 (GMT)

Wow! Great! Thanks!

Pages: [1]
WP-Forum by: Fredrik Fahlstad, Version: 2.4
Page loaded in: 0.043 seconds.

  Follow me on twitter