Opened 14 years ago
Closed 14 years ago
#2094 closed Bug (No Bug)
Hex() returns incorrect values
| Reported by: | SilentButeo2 | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.8.0 | Severity: | None |
| Keywords: | Hex | Cc: |
Description
running next script gives incorrect values (always expecting 4)
$_result_ = "01020304" MsgBox(0,"",StringLen($_result_)/2) ; -> result 4 MsgBox(0,"",Hex(StringLen($_result_)/2,2)) ; -> result 00 MsgBox(0,"",Hex(8/2,2)) ; -> result 00 MsgBox(0,"",Hex(Int(8/2),2)) ; -> result 04 MsgBox(0,"",StringLen($_result_)/2) ; -> result 4 MsgBox(0,"",Hex(StringLen($_result_)/2)) ; -> result 4010000000000000 MsgBox(0,"",Hex(8/2)) ; -> result 4010000000000000 MsgBox(0,"",Hex(Int(8/2))) ; -> result 00000004
Attachments (0)
Change History (9)
comment:1 by , 14 years ago
follow-ups: 3 4 comment:2 by , 14 years ago
I did a bit of testing and it is not Hex fault.
I found that StringLen does not return an integer - see example:
$string = "aaaa" $var = StringLen($string)/2 MsgBox(0, "$var - StringLen", $var) MsgBox(0, "Hex $var", Hex($var, 2)) $var = int(StringLen($string)/2) MsgBox(0, "$var - Int(StringLen)", $var) MsgBox(0, "Hex $var", Hex($var, 2))
When Transforming the result using "Int", everything works as intended.
comment:3 by , 14 years ago
Replying to enaiman:
I did a bit of testing and it is not Hex fault.
I found that StringLen does not return an integer - see example:
$string = "aaaa" $var = StringLen($string)/2 MsgBox(0, "$var - StringLen", $var) MsgBox(0, "Hex $var", Hex($var, 2)) $var = int(StringLen($string)/2) MsgBox(0, "$var - Int(StringLen)", $var) MsgBox(0, "Hex $var", Hex($var, 2))When Transforming the result using "Int", everything works as intended.
Not entirely convinced:
$_result_ = "01020304" ConsoleWrite(IsInt(StringLen($_result_))&@CRLF) ; -> returns 1 (=True)
and it does not explain next outcome
MsgBox(0,"",Hex(8/2)) ; -> result 4010000000000000
comment:4 by , 14 years ago
Replying to enaiman:
I did a bit of testing and it is not Hex fault.
I found that StringLen does not return an integer - see example:
$string = "aaaa" $var = StringLen($string)/2 MsgBox(0, "$var - StringLen", $var) MsgBox(0, "Hex $var", Hex($var, 2)) $var = int(StringLen($string)/2) MsgBox(0, "$var - Int(StringLen)", $var) MsgBox(0, "Hex $var", Hex($var, 2))When Transforming the result using "Int", everything works as intended.
Not true stringlen is ok but as you divide by 2 you get a float/double in $var
follow-up: 6 comment:5 by , 14 years ago
In fact displaying an integer does not mean that the internal value is an integer.
In this specific case the division by 2 make the internal result a double.
So when you get part of the representation of a double is not the the same a getting part of an integer.
You can see that Hex(..., n) is taking the right n bytes of the hex internal represention.
NO BUG
comment:6 by , 14 years ago
Replying to Jpm:
In fact displaying an integer does not mean that the internal value is an integer.
In this specific case the division by 2 make the internal result a double.
So when you get part of the representation of a double is not the the same a getting part of an integer.
You can see that Hex(..., n) is taking the right n bytes of the hex internal represention.
NO BUG
And how do you explain the difference in output between version v3.3.6.1 and v3.3.8.0?
v3.3.8.0
$_result_ = "01020304" ConsoleWrite(IsInt(StringLen($_result_))&@CRLF) MsgBox(0,"",StringLen($_result_)/2) ; -> result 4 MsgBox(0,"",Hex(StringLen($_result_)/2,2)) ; -> result 00 MsgBox(0,"",Hex(8/2,2)) ; -> result 00 MsgBox(0,"",Hex(Int(8/2),2)) ; -> result 04 MsgBox(0,"",StringLen($_result_)/2) ; -> result 4 MsgBox(0,"",Hex(StringLen($_result_)/2)) ; -> result 4010000000000000 MsgBox(0,"",Hex(8/2)) ; -> result 4010000000000000 MsgBox(0,"",Hex(Int(8/2))) ; -> result 00000004
v3.3.6.1
$_result_ = "01020304" ConsoleWrite(IsInt(StringLen($_result_))&@CRLF) MsgBox(0,"",StringLen($_result_)/2) ; -> result 4 MsgBox(0,"",Hex(StringLen($_result_)/2,2)) ; -> result 04 MsgBox(0,"",Hex(8/2,2)) ; -> result 04 MsgBox(0,"",Hex(Int(8/2),2)) ; -> result 04 MsgBox(0,"",StringLen($_result_)/2) ; -> result 4 MsgBox(0,"",Hex(StringLen($_result_)/2)) ; -> result 00000004 MsgBox(0,"",Hex(8/2)) ; -> result 00000004 MsgBox(0,"",Hex(Int(8/2))) ; -> result 00000004
Additionally, it make no sense that Hex(8/2,2) results in 00
I still think this is a BUG.
comment:7 by , 14 years ago
The hex change in 3.3.8.0 make support of all internal type. Previously double seems to be converted to integer.
It may be a script breaking but the new behavior is the correct one no internal change to var type.
it you want to be convinced that not just not return the left 4 just try
MsgBox(0,"8/4.000000000000001",8/4.000000000000001) ; -> result 2 MsgBox(0,"Hex(8/4.000000000000001,2)",Hex(8/4.000000000000001,2)) ; -> result FE MsgBox(0,"Hex(8/4.000000000000001)",Hex(8/4.000000000000001)) ; -> result 3FFFFFFFFFFFFFFE
comment:8 by , 14 years ago
Ok, I understand why it is given the different output.
I think this will break many scripts, but if this is the correct implementation, than that is the price we have to pay for it. Once all scripts/UDF's are fixed, this is no issue anymore.
This ticket can be closed.
comment:9 by , 14 years ago
| Resolution: | → No Bug |
|---|---|
| Status: | new → closed |

Problem is introduce in v3.3.8.0
With v3.3.6.1 all calls return 4 (or 04)
running this on Windows 7 32-bit