hex to decimal?

1. Member
Join Date
Dec 1969
Posts
46

## hex to decimal?

Is there any built in function in vbscript or an easy way to convert a hex number to a decimal number?

2. Senior Member
Join Date
Dec 1969
Posts
946

## RE: hex to decimal?

I know there are function to convert decimal to Hex and Oct, but the reverse... you have to code one or just find one on Google.<BR><BR>Try this:<BR>http://www.sonofsofaman.com/hobbies/code/hextodec.asp<BR><BR>Regards,<BR><BR>Vadim C.

3. Senior Member
Join Date
Dec 1969
Posts
946

## PS.. even nicer

I haven&#039;t tried it out... yes.. being lazy.. but this one is even shorter, to the point:<BR><BR>Function HexToDec(ByVal sHex)<BR>HexToDec = "" & CLng("&H" & sHex)<BR>End Function<BR><BR>You&#039;ll get a run-time error if the string is not hex or if the conversion produces an overflow. <BR><BR>So perhaps the first solution will be better for you... <BR><BR>Vadim C.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Why the extraneous concatenation?

Function HexToDec(ByVal sHex)<BR> HexToDec = [hl="pink"]"" &[/hl] CLng("&H" & sHex)<BR>End Function<BR><BR>??? why the stuff in pink???<BR><BR>That converts the nice number you got from CLNG into a string! So that means that if you want to do any math with the result of calling that function you have to call CLNG, *again*, to convert it back from string to number.<BR><BR>Leave it as a number. If the caller *needs* it as a string, likely he/she won&#039;t need to do anything at all with it (e.g., if you Response.Write a number, it gets converted to a string automatically).<BR><BR>

#### Posting Permissions

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