Integer to Char conversion?
travis
Posts: 180
I have another type conversion question:
I need ValueToSend to be a Char that looks like: ( 0xFF 0xF6 0x00 0x00 )
PercentValue ranges from -100 to +100
Basically I'm trying to go from 0xFFF600 to {0xFF, 0xF6, 0x00}
Sidenote: why does the above code get this warning?
WARNING: C10571: Converting type [SINTEGER] to [LONG]
I didn't define ValueToSend as SLONG for my health?
DEFINE_VARIABLE SINTEGER PercentValue SLONG ValueToSend DEFINE_START PercentValue = -10 ValueToSend = PercentValue * 65536
I need ValueToSend to be a Char that looks like: ( 0xFF 0xF6 0x00 0x00 )
PercentValue ranges from -100 to +100
Basically I'm trying to go from 0xFFF600 to {0xFF, 0xF6, 0x00}
Sidenote: why does the above code get this warning?
WARNING: C10571: Converting type [SINTEGER] to [LONG]
I didn't define ValueToSend as SLONG for my health?
0
Comments
Try first making PercentValue an SLONG; that may be enough to fix it. If you need that to be an SINTEGER for other parts of the code and the conversion will mess you up, assign it to a temporary value with the TYPE_CAST function and do your math on that.
This is a case of automatic type conversions not doing what you expect. In all such cases, you have to force the issue so the compiler will do what you want. Some of the conversion rules are pretty arcane, and it often take a bit of fiddling to get what you want out of it. The rules as posted in the help file, are incomplete and somewhat vague in places.
that's why I'm here. Thanks for your help.
I tried to simplify even more to figure out what is going on. Now I'm dismayed:
wat?
BigSignedNumber = TYPE_CAST(-65536)
works, though by all rights you shouldn't have to do it. Apparently, it's not seeing the - sign when evaluating the expression for conversion.
I just noticed
BigSignedNumber = -65535
doesn't cause the warning
anyways, here's how i ended up converting from integer to character:
I'm really stuck. I can't get from a Signed Long to a string .
I need be able to send the number 0xFFF60000 or 0x00A00000 out to a device including all the leading and trailing zeros.
For example would look like "FF, F6, 00, 00" going out through send_string
To send out an SLONG as four bytes (assuming big-endian byte order):
anyways, here's the relevant part of the protocol