Count in octal: Difference between revisions
Content added Content deleted
(→{{header|BQN}}: Mention simpler method that doesn't fit the problem description) |
(Added uBasic/4tH version) |
||
Line 877: | Line 877: | ||
130 LET N$="1"+N$ |
130 LET N$="1"+N$ |
||
140 GOTO 20</lang> |
140 GOTO 20</lang> |
||
==={{header|uBasic/4tH}}=== |
|||
This routine allows for any base (up to 36) and also caters for negative numbers. |
|||
<lang>x = 1 |
|||
Do |
|||
Print Show(FUNC(_FNtobase(x, 8))) |
|||
While Set (x, x+1) |
|||
Loop |
|||
End |
|||
_FNtobase |
|||
Param (2) ' convert A@ to string in base B@ |
|||
Local (2) ' digit C@ and string D@ |
|||
' initialize, save sign |
|||
d@ = Dup("") : Push a@ < 0 : a@ = Abs(a@) |
|||
Do |
|||
c@ = a@ % b@ : a@ = a@ / b@ ' extract digit and append |
|||
d@ = Join (Char (Ord("0") + c@ + (7 * (c@ > 9))), d@) |
|||
While a@ > 0 ' something left to convert? |
|||
Loop |
|||
If Pop() Then d@ = Join ("-", d@) ' apply sign if required |
|||
Return (d@) |
|||
</lang> |
|||
=={{header|Batch File}}== |
=={{header|Batch File}}== |