Convert HEX to Decimal

# Thread: Convert HEX to Decimal

1. Senior Member
Join Date
Dec 1969
Posts
123

## Convert HEX to Decimal

Is there an easy way to convert hexadecimal numbers to decimal? In other words, if HEX(75) converts the decimal number 75 to 4B in hexadecimal format, is there an easy way to convert it back to decimal format?

2. Senior Member
Join Date
Dec 1969
Posts
339

## RE: Convert HEX to Decimal

I think there is a built in function for it..?

3. Senior Member
Join Date
Dec 1969
Posts
339

## RE: Convert HEX to Decimal

http://www.devguru.com/Technologies/vbscript/quickref/hex.html

4. Senior Member
Join Date
Dec 1969
Posts
123

## RE: Convert HEX to Decimal

Hey Kodo, thanks, but that page shows how to convert from decimal to hexadecimal. I want to convert from hexadecimal to decimal.

5. Senior Member
Join Date
Dec 1969
Posts
11,334

## Just use CInt()

dim x, y<BR>x = &H8B<BR>y = CINT(x)<BR><BR>Response.Write y<BR><BR>You&#039;ll see 139.

6. Senior Member
Join Date
Dec 1969
Posts
123

## Thanks

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

## Ummm...you don't NEED CInt...

...in the code that DG showed!<BR><BR>Try this code to see what I mean:<BR>&#060;%<BR>dim x<BR>x = &H8B<BR>Response.Write "x is a variable of type " & TypeName(x) _<BR>&nbsp; &nbsp; & " and x has value " & x & "&#060;p&#062;"<BR>%&#062;<BR><BR>I *think* that what DG *meant* to show was this:<BR><BR>&#060;%<BR>Dim x, y<BR>x = "&H" & Hex( anyNumber )<BR>y = CLng( x )<BR>Response.Write y<BR>%&#062;<BR><BR>*Now* you are converting a *string* to a number.<BR><BR>I might point out that CINT will *only* handle hex values from 0000 to FFFF. If you need to go outside that range, you can use CLNG for hex values from 00000000 to FFFFFFFF. <BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
123

## RE: Ummm...you don't NEED CInt...

Thanks Bill. Actually, I did find that CINT had a limit. Thanks for the tip.<BR>

9. Senior Member
Join Date
Dec 1969
Posts
11,334

## Yeah, but I still would've had a mistake

I *meant*<BR><BR>somevar = Hex(somenumber)<BR><BR>Since I used CInt cause Hex returns a string.<BR><BR>I forgot to concatenate the &H on it, which would&#039;ve been bad.

#### Posting Permissions

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