Group:  Microsoft Access ยป microsoft.public.access.modulescoding
Thread: Convert Hex to Decimal

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Convert Hex to Decimal
Jake 28.09.2006 21:13:01
Does anyone know of an easy way to convert a Hex number to a Decimal? These
numbers would be large, with a typical length of 13-15 characters.

Thanks!
Re: Convert Hex to Decimal
"Tom Lake" <tlake[ at ]twcny.rr.com> 28.09.2006 23:40:44

"Jake" <Jake[ at ]discussions.microsoft.com> wrote in message
news:BE93B79D-30DB-446B-93B8-D826A3A59DD7[ at ]microsoft.com...
[Quoted Text]
> Does anyone know of an easy way to convert a Hex number to a Decimal?
> These
> numbers would be large, with a typical length of 13-15 characters.
>
> Thanks!

Val("&H" & [HexDigits])

Tom Lake


Re: Convert Hex to Decimal
Marshall Barton <marshbarton[ at ]wowway.com> 29.09.2006 03:33:24
Jake wrote:

[Quoted Text]
>Does anyone know of an easy way to convert a Hex number to a Decimal? These
>numbers would be large, with a typical length of 13-15 characters.


Don't know what you can do with such a large number. but I
think this gives you the best chance:

CDec("&H" & hexstringvariable)

--
Marsh
MVP [MS Access]
Re: Convert Hex to Decimal
"Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> 29.09.2006 04:42:46
If those don't work, let me know and I can post code tomorrow. Converting
Hex to Decimal is fairly straightforward, though as previously pointed out,
large numbers can be tricky to handle in VB, so I may be speaking too soon.
:)


Rob

"Marshall Barton" <marshbarton[ at ]wowway.com> wrote in message
news:4o4ph29crf7n5h0ip57bomgf0u10t0d8vp[ at ]4ax.com...
[Quoted Text]
> Jake wrote:
>
>>Does anyone know of an easy way to convert a Hex number to a Decimal?
>>These
>>numbers would be large, with a typical length of 13-15 characters.
>
>
> Don't know what you can do with such a large number. but I
> think this gives you the best chance:
>
> CDec("&H" & hexstringvariable)
>
> --
> Marsh
> MVP [MS Access]


Re: Convert Hex to Decimal
"Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> 29.09.2006 14:24:15
The Val("&H...") function maxes out a little early for the size of numbers
you're interested in. Here's a function that'll handle extremely large
numbers:

Public Function HexToDec(ByVal strHex As String) As Variant
Const cstrHexDigits As String = "0123456789ABCDEF"
Dim decOut As Variant
Dim i As Integer

decOut = CDec(0)
For i = Len(strHex) To 1 Step -1
decOut = decOut + CDec(16 ^ (Len(strHex) - i)) *
(InStr(cstrHexDigits, Mid$(strHex, i, 1)) - 1)
Next
HexToDec = decOut
End Function

"Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> wrote in message
news:%23zgt6G44GHA.2208[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> If those don't work, let me know and I can post code tomorrow. Converting
> Hex to Decimal is fairly straightforward, though as previously pointed
> out, large numbers can be tricky to handle in VB, so I may be speaking too
> soon. :)
>
>
> Rob
>
> "Marshall Barton" <marshbarton[ at ]wowway.com> wrote in message
> news:4o4ph29crf7n5h0ip57bomgf0u10t0d8vp[ at ]4ax.com...
>> Jake wrote:
>>
>>>Does anyone know of an easy way to convert a Hex number to a Decimal?
>>>These
>>>numbers would be large, with a typical length of 13-15 characters.
>>
>>
>> Don't know what you can do with such a large number. but I
>> think this gives you the best chance:
>>
>> CDec("&H" & hexstringvariable)
>>
>> --
>> Marsh
>> MVP [MS Access]
>
>


Re: Convert Hex to Decimal
Jake 29.09.2006 14:56:02
Thanks Robert - it worked perfectly!

"Robert Morley" wrote:

[Quoted Text]
> The Val("&H...") function maxes out a little early for the size of numbers
> you're interested in. Here's a function that'll handle extremely large
> numbers:
>
> Public Function HexToDec(ByVal strHex As String) As Variant
> Const cstrHexDigits As String = "0123456789ABCDEF"
> Dim decOut As Variant
> Dim i As Integer
>
> decOut = CDec(0)
> For i = Len(strHex) To 1 Step -1
> decOut = decOut + CDec(16 ^ (Len(strHex) - i)) *
> (InStr(cstrHexDigits, Mid$(strHex, i, 1)) - 1)
> Next
> HexToDec = decOut
> End Function
>
> "Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> wrote in message
> news:%23zgt6G44GHA.2208[ at ]TK2MSFTNGP04.phx.gbl...
> > If those don't work, let me know and I can post code tomorrow. Converting
> > Hex to Decimal is fairly straightforward, though as previously pointed
> > out, large numbers can be tricky to handle in VB, so I may be speaking too
> > soon. :)
> >
> >
> > Rob
> >
> > "Marshall Barton" <marshbarton[ at ]wowway.com> wrote in message
> > news:4o4ph29crf7n5h0ip57bomgf0u10t0d8vp[ at ]4ax.com...
> >> Jake wrote:
> >>
> >>>Does anyone know of an easy way to convert a Hex number to a Decimal?
> >>>These
> >>>numbers would be large, with a typical length of 13-15 characters.
> >>
> >>
> >> Don't know what you can do with such a large number. but I
> >> think this gives you the best chance:
> >>
> >> CDec("&H" & hexstringvariable)
> >>
> >> --
> >> Marsh
> >> MVP [MS Access]
> >
> >
>
>
>
Re: Convert Hex to Decimal
"Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> 29.09.2006 15:06:17
The one limitation of it, which I should've mentioned, is that it'll happily
screw up royally if you try to pass it a "normal" string...such as
HexToDec("Jackdaws love my big sphinx of quartz"). If there's any chance
that what gets passed won't be a hex number, you'll want to add some
checking to the function.



Rob

"Jake" <Jake[ at ]discussions.microsoft.com> wrote in message
news:CDC0D024-B0C1-4D40-848B-031A12B61F1F[ at ]microsoft.com...
[Quoted Text]
> Thanks Robert - it worked perfectly!
>
> "Robert Morley" wrote:
>
>> The Val("&H...") function maxes out a little early for the size of
>> numbers
>> you're interested in. Here's a function that'll handle extremely large
>> numbers:
>>
>> Public Function HexToDec(ByVal strHex As String) As Variant
>> Const cstrHexDigits As String = "0123456789ABCDEF"
>> Dim decOut As Variant
>> Dim i As Integer
>>
>> decOut = CDec(0)
>> For i = Len(strHex) To 1 Step -1
>> decOut = decOut + CDec(16 ^ (Len(strHex) - i)) *
>> (InStr(cstrHexDigits, Mid$(strHex, i, 1)) - 1)
>> Next
>> HexToDec = decOut
>> End Function
>>
>> "Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> wrote in message
>> news:%23zgt6G44GHA.2208[ at ]TK2MSFTNGP04.phx.gbl...
>> > If those don't work, let me know and I can post code tomorrow.
>> > Converting
>> > Hex to Decimal is fairly straightforward, though as previously pointed
>> > out, large numbers can be tricky to handle in VB, so I may be speaking
>> > too
>> > soon. :)
>> >
>> >
>> > Rob
>> >
>> > "Marshall Barton" <marshbarton[ at ]wowway.com> wrote in message
>> > news:4o4ph29crf7n5h0ip57bomgf0u10t0d8vp[ at ]4ax.com...
>> >> Jake wrote:
>> >>
>> >>>Does anyone know of an easy way to convert a Hex number to a Decimal?
>> >>>These
>> >>>numbers would be large, with a typical length of 13-15 characters.
>> >>
>> >>
>> >> Don't know what you can do with such a large number. but I
>> >> think this gives you the best chance:
>> >>
>> >> CDec("&H" & hexstringvariable)
>> >>
>> >> --
>> >> Marsh
>> >> MVP [MS Access]
>> >
>> >
>>
>>
>>


Re: Convert Hex to Decimal
Tim Ferguson <FergusonTG[ at ]softhome.net> 29.09.2006 19:57:42
=?Utf-8?B?SmFrZQ==?= <Jake[ at ]discussions.microsoft.com> wrote in
news:BE93B79D-30DB-446B-93B8-D826A3A59DD7[ at ]microsoft.com:

[Quoted Text]
> Does anyone know of an easy way to convert a Hex number to a Decimal?
> These numbers would be large, with a typical length of 13-15
> characters.
>

This will deal with arbitrary length, as long as you don't exceed the
size of a Double:

Public Function HexToDouble(SomeHex As String) As Double

Const digits As String = "0123456789ABCDEF"

If Len(SomeHex) = 0 Then
HexToDouble = 0

Else
HexToDouble = _
HexToDouble(Left(SomeHex, Len(SomeHex) - 1)) * 16 + _
InStr(digits, Mid(SomeHex, Len(SomeHex), 1)) - 1

End If

End Function



There's no error trapping for illegal digits, you just get the wrong
answer.

Hope it helps

Tim F

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net