Solved

Unsigned Long Integer

Posted on 2007-04-11
13
328 Views
Last Modified: 2010-04-23
I extracted this info. from an ECM and is an Odometer for the vehicle:  245 128 92 40 195 01 09  The '245 128' states that it's for the engine info pertaining to odometer, the 92 40 195 01 is the odometer value, and the 09 is the Two's complement checksum.  I have most of it figured out except for the 92 40 195 01 (odometer number)  My protocol book for the ECM states that it is an 'Unsigned Long Integer' and it is ordered by LSB to MSB (least significant byte to most significant byte)
I don't know how to calculate the Unsigned Long Integer from LSB to MSB.
Here's a example of 2 characters from my book: for this sequence - 128 158 29 1 196 where 29 1 is the data - Book reads: "Due to the specification there are two characters of data and they should be treated like an unsigned integer (16 bits where the bits are grouped into 8 bits and sent in reverse order).  The interpretation of the data bytes 29 and 1 as an unsigned integer is (1 * 2^8) + (29 * 2^0) = 285.  The result must then be scaled by the bit resolution..."

Any help?
0
Comment
Question by:dreinmann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 18890340
can you use currency data type?

ie

Dim s As Currency

s = &H81 * 2 ^ 24 + &HFF * 2 ^ 16 + &HFF * 2 ^ 8 + &HFF
0
 
LVL 4

Expert Comment

by:quiklearner
ID: 18891042
for ease, i would use the function defined in the following api call:

Public Declare Function ntohl Lib "ws2_32.dll" (ByVal netlong As Long) As Long

pass the value to the function and it will reverse the byte order..  If it turns out to be not-quite-right you could try the inverse function:

Public Declare Function htonl Lib "ws2_32.dll" (ByVal hostlong As Long) As Long
0
 
LVL 4

Expert Comment

by:quiklearner
ID: 18891082
for ease, i would use the function defined in the following api call:

Public Declare Function ntohl Lib "ws2_32.dll" (ByVal netlong As Long) As Long

pass the value to the function and it will reverse the byte order..  If it turns out to be not-quite-right you could try the inverse function:

Public Declare Function htonl Lib "ws2_32.dll" (ByVal hostlong As Long) As Long
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:jaynee
ID: 18891203
Is your book example in your second paragraph the same as this one?
http://db.s2.chalmers.se/download/masters/master_013_2003.pdf

If so, its talking about only 2 characters, and its probably confusing you more than helping you 'cos you have 4 characters:
92 40 195 01

Now, I'm guessing that we're talking about four bytes here, but I don't know what they're being represented in. Does your ECM protocol book confirm this?
  The reason I ask is that if I assume that they're in decimal, then the ordering from least to most means that the result (ie the odometer reading) would be the sum of:
(92*2^0) + (40*2^1) + (195*2^2) + (1*2^3)
= 92 + 80 + 780 + 8
= 960
In binary, that's 1111000000
To find the 2's complement, invert the bits then add 1.
Unfortunately, the 2's complement of 960 is
00001000000 = 64, not 09!

So I need some more info - are you sure that "92 40 195 01 is the odometer value", and if it is, are those decimal representations of a 4 byte integer?
0
 
LVL 4

Expert Comment

by:quiklearner
ID: 18891288
let do this; what mileage is 92 40 195 01 equal to in integer terms? 29567068? 1546175233?
0
 

Author Comment

by:dreinmann
ID: 18893135
Figured it out from some other data extracted from the ECM.  Data:  128 84 0 91 0 245 4 49 81 10 0 76
In this sequence of data 49 81 10 0 is the odometer or 31 51 0A 00 in hex.  Put this in reverse order(LSB)- 000A5131 and convert it back to decimal = 676145.   The bit resolution is 0.1mi, so the odometer is 67614.5 miles.  This matches exactly what the actual odometer reads.
With this Hex conversion, I don't have to know all about Unsigned Long Integers, but nevertheless I've learned what they are and how they work.
Thanks for the answers!
0
 
LVL 4

Expert Comment

by:quiklearner
ID: 18893158
no problem..  Good luck!
0
 
LVL 4

Expert Comment

by:quiklearner
ID: 18893166
quick question though:  so 92 40 195 01 = 29567068 right?
0
 

Author Comment

by:dreinmann
ID: 18893227
Yes, I put 92 40 195 01 through the same equation and it does equal 29567068.  Which one of your function's made that work?
0
 

Author Comment

by:dreinmann
ID: 18893259
I tried that function...I must not have the "ws2_32.dll" file?
0
 
LVL 4

Expert Comment

by:quiklearner
ID: 18893299
actually neither of the api calls would do it:  I have another function i wrote that looks something like:
dim x as long, lPoint as long, sRes as long
x = 1
for lpoint = endingpos to startingpos step -1

next lpoint
0
 
LVL 4

Expert Comment

by:quiklearner
ID: 18893325
dim x as long, lPoint as long, lRes as long
x = 1
for lpoint = endingpos to startingpos step -1
    lres = lres + (itematposition(lpoint) * x)
    x=x*256
next lpoint

is how i have done it in the past where lRes is tha answer..  I just wanted to first verify which direction i was going...
0
 
LVL 4

Expert Comment

by:quiklearner
ID: 18893336
actually now that i reread it it would be:
dim x as long, lPoint as long, lRes as long
x = 1
for lpoint = startingpos to endingpos
    lres = lres + (itematposition(lpoint) * x)
    x=x*256
next lpoint
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Remove Exif Orientation before adding image to db 9 63
Asp.Net Session Question 2 49
reading an excel file vb.net 2 47
Read top line from CSV file 14 59
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question