Previous Thread
Next Thread
Print Thread
Fn'Hex2Dec() issue #36859 05 Dec 23 07:32 PM
Joined: Nov 2006
Posts: 2,192
S
Stephen Funkhouser Online Content OP
Member
OP Online Content
Member
S
Joined: Nov 2006
Posts: 2,192
I'm seeing an issue where Fn'Hex2Dec() is returning a negative value when the bitmask has a value in the leftmost position with an 8 character mask.

If I pass the string bitmask for TROP_ATE "0x08000000" it returns the correct value of 134217728.

Now I pass in the value for TROP_EXEC "0x80000000" it returns a negative -2147483648 instead of the expected positive value

And, the equivalent miame.ini - TRACE=INOUT,BASERR,SIGHUP,EXEC is "0x80018020", the expected decimal value is 2147581984, but it returning -2147385312.

Ashell version EL7 6.5.1739.2
fnhex2dec.bsi is the latest v105

Guessing this is an issue in MX_GTOCT.


Stephen Funkhouser
Diversified Data Solutions
Re: Fn'Hex2Dec() issue [Re: Stephen Funkhouser] #36860 05 Dec 23 08:23 PM
Joined: Jun 2001
Posts: 11,645
J
Jack McGregor Online Content
Member
Online Content
Member
J
Joined: Jun 2001
Posts: 11,645
Right - it's using a 32 bit signed integer and thus treating it as a negative value if the high bit is set. Surprising that it has taken this long to identify!

The fix will show up in 7.0.1752.3 shortly.

Re: Fn'Hex2Dec() issue [Re: Stephen Funkhouser] #36861 05 Dec 23 09:45 PM
Joined: Nov 2006
Posts: 2,192
S
Stephen Funkhouser Online Content OP
Member
OP Online Content
Member
S
Joined: Nov 2006
Posts: 2,192
I can't update the production server this code needs to run on to 7 at this point. I'll have to modify the function to do the conversion in basic. It'll be interesting to see how much slower it is than in C


Stephen Funkhouser
Diversified Data Solutions
Re: Fn'Hex2Dec() issue [Re: Stephen Funkhouser] #36862 05 Dec 23 10:44 PM
Joined: Jun 2001
Posts: 11,645
J
Jack McGregor Online Content
Member
Online Content
Member
J
Joined: Jun 2001
Posts: 11,645
Actually, Fn'Hex2Dec() is nearly obsolete ever since ASB started recognizing "&h" and "&o" prefixes when converting from string to numeric. So the function could be reduced to:

Code
significance 11
++include'once ashinc:ashell.def

    ? Fn'Hex2Dec(TROP_EXEC)
    end

Function Fn'Hex2Dec(hexval$ as s20) as b6
    .fn = hexval$
EndFunction

If anything, it might even be faster than the MX_GTOCT version!
(Although I should note that this approach only works if the input string has the properly &h or &o prefix! But if it didn't, you could always test for it and add it before doing the assignment to the numeric variable.)

Last edited by Jack McGregor; 05 Dec 23 11:02 PM. Reason: addendum
Re: Fn'Hex2Dec() issue [Re: Stephen Funkhouser] #36863 05 Dec 23 11:32 PM
Joined: Jun 2001
Posts: 11,645
J
Jack McGregor Online Content
Member
Online Content
Member
J
Joined: Jun 2001
Posts: 11,645
Wait - the above example is misleading. The symbol TROP_EXEC is defined as 0x80000000, but gets resolved into a regular numeric value by the define statement. What you really want is to convert a hex representation to decimal, so the example should be more like:
Code
significance 11
++include'once ashinc:ashell.def

    ? Fn'Hex2Dec("80000000")
    end

Function Fn'Hex2Dec(hexval$ as s20) as b6
    if hexval$[1,2] # "&h" then
        hexval$ = "&h" + hexval$
    endif
    .fn = hexval$
EndFunction

Re: Fn'Hex2Dec() issue [Re: Stephen Funkhouser] #36864 07 Dec 23 09:56 PM
Joined: Nov 2006
Posts: 2,192
S
Stephen Funkhouser Online Content OP
Member
OP Online Content
Member
S
Joined: Nov 2006
Posts: 2,192
I can confirm that works as advertised.


Stephen Funkhouser
Diversified Data Solutions

Moderated by  Jack McGregor, Ty Griffin 

Powered by UBB.threads™ PHP Forum Software 7.7.3