Announcement

Collapse
No announcement yet.

Dword troubles

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dword troubles

    Hello everyone,

    i need to convert a 32bit Dword value to Hex, using hex$ for that.
    I tested some using the following code:

    dim a as dword
    a=val("&b"+"0"+string$(32,"1") ' unsigned 32 bits
    print a ' works nice, displays correct value
    print hex$(a) ' causes overflow

    this leads to an overflow. if i change the 32 in the string$ function
    to 31 all goes well. may i conclude from this that 32bit values cannot
    be converted to hex? thanx for any info on this.

    Tom

    ------------------
    [URL=http://www.DiyDataRecovery.nl]

  • #2
    HEX$() is implicitly limited to the signed LONG integer range (&H7FFFFFFF??? = 2147483647 = &H07FFFFFFF).

    Since the unsigned value of &HFFFFFFFF??? is larger than the maximum LONG value that you want to convert to HEX, you'll need to break it into two 16-bit parts to convert it successfully:
    Code:
    dim a as dword
    a=val("&b"+"0"+string$(32,"1")) ' unsigned 32 bits
    print a ' works nice, displays correct value
    print hex$(a \ &H10000??) + hex$(a mod &H10000??)
    (Note that your code is missing a closing parenthesis on the "a=" line).

    I hope this helps.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      It does. thank you.

      ------------------
      [URL=http://www.DiyDataRecovery.nl]

      Comment

      Working...
      X