Announcement

Collapse
No announcement yet.

Decimal to hexadecimal routine

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

  • 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.

  • #2
    How about... x$ = hex$(y&)

    Bob Zale
    PowerBASIC Inc.



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

    Comment


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

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

      Comment


      • #4
        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.
        Alan C. Earnshaw
        Information Management Systems, Inc.
        http://www.infoms.com

        Comment


        • #5
          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>
          Lance
          mailto:[email protected]

          Comment

          Working...
          X