 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
New_G Guest
|
Posted: Sat Apr 02, 2005 7:33 am Post subject: How to convert an integer from decimal to Octal?! |
|
|
hi,
I need to convert an integer from decimal to octal
is that possible by using ahk?!
thanks for help! |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Sat Apr 02, 2005 12:14 pm Post subject: |
|
|
| Not directly, you would have to write a subroutine that does it mathematically. |
|
| Back to top |
|
 |
lost
Joined: 08 Mar 2005 Posts: 10
|
Posted: Sat Apr 02, 2005 3:35 pm Post subject: |
|
|
Hi,
| Code: | inputbox,cn
ocn=
loop
{
transform,x,mod,cn,8
stringleft,x,x,1
ocn=%x%%ocn%
cn:=(cn-x)/8
if cn<8
{
stringleft,cn,cn,1
ocn=%cn%%ocn%
break
}
}
msgbox %ocn% |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Sat Apr 02, 2005 3:38 pm Post subject: |
|
|
| Snazzy! |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Sat Apr 02, 2005 7:34 pm Post subject: |
|
|
But he's lost !  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Sat Apr 02, 2005 10:27 pm Post subject: |
|
|
Nice!
Minor issue: single digit results have a 0 prefix, others not. We can fix it and simplify the loop slightly: | Code: | Loop
{
Transform x, mod, cn, 8
ocn = %x%%ocn%
Transform cn, BitShiftRight, cn, 3
IfLess cn,1, break
} | Negative numbers are not converted correctly, but at least, there is no infinite loop. If you need negative octals, insert the following in front of the Loop | Code: | IfLess cn,0, {
sign = -
cn := -cn
} | The result is |
|
| Back to top |
|
 |
lost
Joined: 08 Mar 2005 Posts: 10
|
Posted: Sun Apr 03, 2005 4:33 am Post subject: |
|
|
Hi,
Laszlo
| Quote: |
Minor issue: single digit results have a 0 prefix, others not
|
yes .. I changed the order of the code without changing the code itself
I hope that could fix it..! thanks
| Code: |
inputbox,cn
ocn=
loop
{
if cn<8
{
stringleft,cn,cn,1
ocn=%cn%%ocn%
break
}
transform,x,mod,cn,8
stringleft,x,x,1
ocn=%x%%ocn%
cn:=(cn-x)/8
}
msgbox %ocn%
|
Laszlo
| Quote: |
Negative numbers are not converted correctly
|
In fact I didn't try any negative numbers. but there 're many ways to fix this bug if anyone needs to use negative values.
Tthanks |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|