Weird Quirk with ITOA
alexanbo
Junior Member
Was doing some troubleshooting on a CRC calculation and noticed that when I used ITOA to show some data it gave me some odd results
Returned:
Test 1:16776960
Test 2:0
Which is odd because I expected Test 1 to be $FF00 not $FFFF00. In digging I found that ITOA's parameter is actually a Long which kinda explains the first result, but then it's not consistent with the second result?
button_event[10128:1:0,1]
{
push:
{
stack_var integer crc
crc = $ffff
send_string 0,"'Test 1:',itoa(crc << 8)"
send_string 0,"'Test 2:',itoa(crc + 1)"
}
}
Returned:
Test 1:16776960
Test 2:0
Which is odd because I expected Test 1 to be $FF00 not $FFFF00. In digging I found that ITOA's parameter is actually a Long which kinda explains the first result, but then it's not consistent with the second result?
Comments
-
If you change:
send_string 0,"'Test 1:',itoa(crc << 8)"
To this equivalent:
send_string 0,"'Test 1:',itoa(crc * 256)"
Then you get the expected result of 65280 ($FF00)
Weird indeed.Was doing some troubleshooting on a CRC calculation and noticed that when I used ITOA to show some data it gave me some odd resultsbutton_event[10128:1:0,1] { push: { stack_var integer crc crc = $ffff send_string 0,"'Test 1:',itoa(crc << 8)" send_string 0,"'Test 2:',itoa(crc + 1)" } }
Returned:
Test 1:16776960
Test 2:0
Which is odd because I expected Test 1 to be $FF00 not $FFFF00. In digging I found that ITOA's parameter is actually a Long which kinda explains the first result, but then it's not consistent with the second result? -
It might be an odd behavior of the bitwise shove (<<) as opposed to itoa. What happens if you remove itoa and just print the numbers?
-
I think it is in itoa, because the calcuation was actually being done correctly, just when I tried to print out intemediary values with itoa that it got funky, sort of a Schr?dinger's Cat sort of thing.
For example if you added a line before the print statement
crc = $ffff << 8
and changed the print statement to:
send_string 0,"'Test1:',itoa(crc)"
it would print out the $ff00 decimal equivalent -
I think it is in itoa, because the calcuation was actually being done correctly, just when I tried to print out intemediary values with itoa that it got funky, sort of a Schr?dinger's Cat sort of thing.
For example if you added a line before the print statement
crc = $ffff << 8
and changed the print statement to:
send_string 0,"'Test1:',itoa(crc)"
it would print out the $ff00 decimal equivalent
Yes, because crc is an integer (16 bits).
If you saidSTACK_VAR LONG_INTEGER test test = $ffff << 8 // or test = $ffff * 256
then the result is $ffff00, because test is a 32-bit integer.
It's nothing to do with itoa aside from the fact that its argument is a LONG_INTEGER. The $ffff+1 test may be running into some weird signed/unsigned arithmetic as well.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums