Jump to content
Sign in to follow this  
redndahead

Hex to Decimal

Recommended Posts

redndahead

I see there is a way of turning Decimal to Hex. Is there a way to turn it back from Hex to Decimal?

red

Share this post


Link to post
Share on other sites
tylo

Not built in, but you can feed the string from Hex() back into this func:

Func Hex2Dec($number)
  $len = StringLen($number)
  $number = StringUpper($number)
  $ret = 0
  $fac = 1
  For $i = $len To 1 Step -1
    $n = Asc(StringMid($number, $i, 1)) - 48
    If $n > 9 Then $n = $n - 7
    $ret = $ret + ($n * $fac)
    $fac = $fac * 16
  Next
  Return $ret
EndFunc

/EDIT: removed use of ^ operator: Jon, this is straight forward to do in C. :whistle:

Edited by tylo

blub

Share this post


Link to post
Share on other sites
redndahead

Thanks Tylo that was exactly what i needed...

I would appreciate it jon that will cut out some unnecessary code.

Thanks everybody again. Give my password encryption program a try.

red

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.