Modify

Opened 13 years ago

Closed 13 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 Changed 13 years ago by SilentButeo2

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 follow-ups: Changed 13 years ago by 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.

comment:3 in reply to: ↑ 2 Changed 13 years ago by SilentButeo2

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 in reply to: ↑ 2 Changed 13 years ago by Jpm

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 13 years ago by Jpm (previous) (diff)

comment:5 follow-up: Changed 13 years ago by 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

comment:6 in reply to: ↑ 5 Changed 13 years ago by SilentButeo2

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 Changed 13 years ago by Jpm

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 13 years ago by Jpm (previous) (diff)

comment:8 Changed 13 years ago by SilentButeo2

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 Changed 13 years ago by Jpm

  • Resolution set to No Bug
  • Status changed from new to closed

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.