How do you convert a byte[32] array to a long?
mre_rob
Posts: 31
If I have this:
var
byte tmp[noparse][[/noparse]32]
long dest
How do I get the byte array moved to the long correctly?
TIA...
var
byte tmp[noparse][[/noparse]32]
long dest
How do I get the byte array moved to the long correctly?
TIA...
Comments
as at the moment dest is 1 long ( 4 bytes ) so therefore tmp ( being 32 bytes ) could not be squeezed into it, unless dest was a pointer to a buffer for 8 longs.
or, you could mean, there's an ascii string number stored in tmp, that you want converting to a long? ie "1234567890" you want it converting into one long 1234567890
Baggers.
Now it makes sense....
There is an ascii string stored in tmp and I want to move it to a long. It appears that my size is off, but what would be the syntax to accomplish this type of memory move?
Thx...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)
The string has to be terminated with a zero byte and there's no error checking.
You'd call "dest := convert(@tmp)"
' Minimal error checking -- this will work for NMEA strings, more or less, but you will end up taking in only the integer part of a value. If you want, get the navcom ai source (see my sig) and use the ParseNextFloat routine that is in FtoF.spin -- does the same thing, only generates a floating point result and has robust error checking.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)
So If I am parsing Lat, then the code would be similar to this to get the correct float
Please assume that "f" is the ftof object and "tmp" has the ascii string to convert
f.ParseNextFloat(@tmp,long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcLat)])
Look like I am on the right track?
TIA..
Rob.
ParseNextInt/ParseNextFloat is optimized to use in GPS strings, because it eats up the digits in the original string (replaces them with ####'s) and returns where to
start looking for the next number if you're in a hurry.
So for example, if you have a NMEA string that has (comma separated) values for lat, lon and heading, you can do
f.ParseNextFloat(@tmp,long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcLat)])
f.ParseNextFloat(@tmp,long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcLon)])
f.ParseNextFloat(@tmp,long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcHeading)])
and it will work. I did this because, obviously, it was supposed to work with nmea or nmea-like strings in the first place. Nifty, no?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)