# Dec To Binary

## Recommended Posts

Alright not so lazy and decided to do it. Must be in between 2 and 62

Here it is

```Func DecConvert(\$dec,\$Div)
If \$div > 62 or \$div < 2 Then
Return(-1)
EndFunc
EndIf
\$ans = ""
\$letterValues = ".........ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
While \$dec > \$Div - 1
\$val = mod(\$dec,\$div)
If \$val > 9 Then
\$val = stringmid(\$LetterValues,\$val,1)
EndIF
\$ans = \$val & \$ans
\$dec = int(\$dec / \$div)
Wend
If \$dec > 9 Then
\$dec = stringmid(\$LetterValues,\$dec,1)
EndIF
Return(\$dec & \$ans)
EndFunc```

Not too bad only 20 lines of code.

red

##### Share on other sites

Fun Test Script

```\$ans = DecConvert(8513821109,60)
MsgBox(0,"",\$ans)
Exit

Func DecConvert(\$dec,\$Div)
If \$div > 62 or \$div < 2 Then
Return(-1)
EndFunc
EndIf
\$ans = ""
\$letterValues = ".........ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
While \$dec > \$Div - 1
\$val = mod(\$dec,\$div)
If \$val > 9 Then
\$val = stringmid(\$LetterValues,\$val,1)
EndIF
\$ans = \$val & \$ans
\$dec = int(\$dec / \$div)
Wend
If \$dec > 9 Then
\$dec = stringmid(\$LetterValues,\$dec,1)
EndIF
Return(\$dec & \$ans)
EndFunc```

By the way did these work for you Lemures? since you were the one that asked for it?

red

##### Share on other sites

Nice You should remove the "EndFunc" that follows Return(-1). It is not needed and AutoIt 3.0.93 complains about it.

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
##### Share on other sites

Didn't know that it automatically returned. Cool saved me a line of code. =) I must say though i haven't tested bartokv's code it is really cool that you can convert anything. Impressive

red

##### Share on other sites

lol, god i love this community.... anyways, using using the dec->bin code, i completed my thingy.. lol... http://www.rage3d.com/board/showthread.php...readid=33741645

see if any of you can figure it ou!

##### Share on other sites

Which function did you end up using?

##### Share on other sites

And anyway who uses anything higher except for base 16?

I agree with you there. I mainly use decimal/hexadecimal, and occasionally binary... (Try to avoid octal whenever possible)

I didn't really post my code as a recommended solution. I just thought about an interesting way achieve the desired results, and decided to post the code strictly for the absurdity factor. ...To paraphrase Larry, I used a sledge hammer to drive a finishing nail.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...