Modify

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 SilentButeo2, 14 years ago

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

comment:2 by enaiman, 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.

in reply to:  2 comment:3 by SilentButeo2, 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

in reply to:  2 comment:4 by J-Paul Mesnage, 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

Last edited 14 years ago by J-Paul Mesnage (previous) (diff)

comment:5 by J-Paul Mesnage, 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

in reply to:  5 comment:6 by SilentButeo2, 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 J-Paul Mesnage, 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
Last edited 14 years ago by J-Paul Mesnage (previous) (diff)

comment:8 by SilentButeo2, 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 J-Paul Mesnage, 14 years ago

Resolution: No Bug
Status: newclosed

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.