Results 1 to 5 of 5

Thread: Convert Hex to Decimal

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    Can someone tell me how to convert an Hexidecimal number to a Decimal number please, as i want to convert a hexadecimal colour of say a form to that of a decimal one...any1 know how?
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Ok, that needed some maintenance, now you can use up to base 201
    Code:
    ' - - - - - - - K E D A M A N S    C O D E- - - - - - -30.5.00 ( updated 9.6.00 )
    ' Base mod decimal converters
    'IE bin 2 dec
    ' Base2dec("1234",2)
    ' oct 2 bin
    ' dec2base(Base2dec("1234",8),2)
    'trin 2 hex
    ' dec2base(Base2dec("1234",3),16)
    Function Base2Dec(val$, base%): Dim n%, a() As Byte
        a = StrConv(UCase(val), vbFromUnicode)
        For n = 1 To Len(val)
            Base2Dec = CDec(Base2Dec + (a(n - 1) - 48 + 7 * (a(n - 1) > 64)) * base ^ (Len(val) - n))
        Next n
    End Function
    Function Dec2Base$(val, base%): Dim n%, s
        For n = 0 To 100
            s = Int(val / base ^ n)
            If s = 0 Then Exit For
            s = s - Int(s / base) * base 's mod base
            Dec2Base = Chr(s + 48 - 7 * (s > 9)) & Dec2Base
        Next n
    End Function
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Junior Member
    Join Date
    Mar 2000
    Posts
    28
    here:

    Function HexToDec(TheHex As String) As Long
    HexToDec = CLng("&H" & TheHex)
    End Function

  5. #5
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Hello Mag-Net,

    Try this source:

    Private Sub Command1_Click()
    Dim Tabel As String
    Dim Temp, N As Integer
    Dim Answer As Long

    Answer = 0
    Tabel = "0123456789ABCDEF"
    'if you want to create Octal to decimal: Tabel = "01234567"

    Text1.Text = UCase(Text1.Text)

    For N = 1 To Len(Text1.Text)
    Temp = InStr(1, Tabel, Mid(Text1.Text, N, 1)) - 1
    Answer = Answer + (16 ^ (Len(Text1.Text) - N)) * Temp
    Next N

    MsgBox Answer
    End Sub


    Good luck,

    Michelle.

    [Edited by michelle on 06-09-2000 at 03:55 AM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width