Announcement

Collapse
No announcement yet.

Decimal to hexadecimal routine

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

  • Lance Edmonds
    replied
    Note that you should prefix the hex string with a leading zero to ensure that the value is treated as an unsigned value:

    A$ = "FFFF"
    PRINT VAL$("&H" + A$)
    PRINT VAL$("&H0" + A$)

    Results:
    -1
    65535

    Also note that VAL() is capable of working with binary and octal strings too:
    A$ = "1010101"
    PRINT VAL("&B0" + A$)
    A$ = "76543"
    PRINT VAL("&O" + A$)


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

    Leave a comment:


  • Alan Earnshaw
    replied
    Fred,

    For the hexadecimal to decimal conversion, use:

    Code:
    x& = VAL("&H" + HexVal$)
    Given the abilities of the PowerBASIC compiler, it will be faster and more efficient than doing the work in Basic code.

    Alan

    ------------------
    Alan C. Earnshaw
    Information Management Systems, Inc.

    Leave a comment:


  • Fred Katzel
    replied
    So simple, I wasn't aware of the function HEX$. Thanks!
    Fred

    ------------------

    Leave a comment:


  • Bob Zale
    replied
    How about... x$ = hex$(y&)

    Bob Zale
    PowerBASIC Inc.



    ------------------

    Leave a comment:


  • Fred Katzel
    started a topic Decimal to hexadecimal routine

    Decimal to hexadecimal routine

    Does anyone have a decimal to hexadecimal routine. I had no problem producing a hexadecimal to decimal routine, but I seem to have run into a problem producing a decimal to hexadecimal routine.
Working...
X