1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

@eval[2**64-1]

Discussion in 'Support' started by vefatica, Jun 6, 2014.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    The second one below ... I don't understand it. Shouldn't it be 0xFFFFFFFFFFFFFFFF?
    Code:
    v:\> echo %@eval[2**64-1]
    18446744073709551615
    
    v:\> echo %@eval[2**64-1=x]
    0x7FFFFFFFFFFFFFFF
    
    v:\> echo %@eval[0x7FFFFFFFFFFFFFFF]
    9223372036854775807
    
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    To put it another way ...
    Code:
    v:\> echo %@eval[18446744073709551615=x]
    0x7FFFFFFFFFFFFFFF
    
    v:\> echo 0x%@convert[10,16,18446744073709551615]
    0xFFFFFFFFFFFFFFFF
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,870
    Likes Received:
    83
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    It's 0/10. But doesn't that deal with what comes after a decimal point?
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,870
    Likes Received:
    83
    Hex values (like integer operators) are int64 (signed 64-bit) max.
     
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    Yeah, but 18446744073709551615 is 0xFFFFFFFFFFFFFFFF and treated an signed, that's -1.

    0x7FFFFFFFFFFFFFFF is the largest positive signed int64, 9223372036854775807. I still can't figure out where it's coming from.

    Code:
    v:\> echo %@eval[18446744073709551615=x]
    0x7FFFFFFFFFFFFFFF
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    Is there a C function or WIN32 function that will turn 18446744073709551615 into 0x7FFFFFFFFFFFFFFF?
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,870
    Likes Received:
    83
    It's coming from the RTL (_wtoi64).
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    I see. _wcstoi64() does the same thing. I still think it's odd. 0 would be a better indication that something of an error (overflow) than _I64_MAX.
     
  10. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,870
    Likes Received:
    83
    I'm not sure I understand why you think it's odd -- you're passing in an argument that's twice the maximum allowed size, and it's getting truncated (by the RTL).

    Do you actually need to convert 64-bit values to hex?
     
  11. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    1. It's just not very informative.

    2. Occasionally.
     
  12. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,870
    Likes Received:
    83
    Apparently not too occasionally, or you would have mentioned it a few years ago!

    I'm afraid you're on your own here -- you can write your own function to do the > 2*64 hex conversions. (But it will not be easy.)
     
  13. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    I already have @CONVERT, which gets it right.
    Code:
    v:\> echo %@eval[2**64-1]
    18446744073709551615
    
    v:\> echo %@convert[10,16,18446744073709551615]
    FFFFFFFFFFFFFFFF
     
  14. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,870
    Likes Received:
    83
    @CONVERT won't work with anything > 2**64, as it also uses int64 variables.
     
  15. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    Well I don't know how it does it but @CONVERT correctly turns 18446744073709551615 (which is less than 2**64) into FFFFFFFFFFFFFFFF. And it turns 18446744073709551614 into FFFFFFFFFFFFFFFE. And so on. Maybe @EVAL's "=x" should assume a positive number is desired and use @CONVERT.
     

Share This Page