China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 12:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Multiplication between two numbers in the same base within decimal, with no digit limit View 1,240 Replies 3
Original Poster Posted 2009-02-21 15:22 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
One of the results produced in the process of writing other batch files. The draft paper is in bathome's chatter section and in cn-dos's blog


Function: multiply two numbers with no digit limit

Input format like 10 20

You can choose a base within 10 for multiplication, such as 100 11 2 , where 2 means binary


@echo off &setlocal enabledelayedexpansion
title code by 523066680
set /p inp="input two numbers : "
call :naxnb %inp%
pause>nul
exit
:naxnb
set numa=%1
set numb=%2
if "%3"=="" (set /a delna=10,delnb=9) else (set /a delna=%3,delnb=%3-1)
set /a la=0,lpr=-1
:la
set /a la+=1,lb=0,lpr+=1,lp=lpr
:lb
set /a lb+=1,lp+=1,tlpa=lp,tlpb=lp+1
:::::::::::::::::::::::::
set /a cup%lp%+=!numa:~-%la%,1! * !numb:~-%lb%,1!
:cuplp
set /a cup%tlpb%+=cup%tlpa%/delna,cup%tlpa%=cup%tlpa%%%delna
if !cup%tlpb%! gtr %delnb% (
set /a tlpa+=1,tlpb=tlpa+1
goto :cuplp
) else (if !cup%tlpb%! equ 0 set /a tlpb-=1)
::::::::::::::::::::::::::
if not "!numb:~%lb%!"=="" (goto :lb)
if not "!numa:~%la%!"=="" (goto :la)
for /l %%a in (%tlpb%,-1,1) do set /p=!cup%%a!<nul



[ Last edited by 523066680 on 2009-5-1 at 23:09 ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
BC +4 2009-02-21 18:58
HAT +4 2009-02-21 19:15
moniuming +5 2009-02-21 20:22
Floor 2 Posted 2009-02-21 18:58 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
Hurry up and split the module out and add it to the function library...
Floor 3 Posted 2009-02-21 20:24 ·  中国 广西 百色 中移铁通
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Originally posted by BC at 2009-2-21 18:58:
Hurry up and split the module out and add it to the function library...

It doesn't support floating-point operations or positive/negative number operations, and you can't define the number of decimal places to keep, so it's not mature enough to make into a function yet...
How about this?
"Batch Function Library"

[ Last edited by moniuming on 2009-2-21 at 20:27 ]
Floor 4 Posted 2009-02-22 11:32 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
So it still needs improvement don't rush everything starts from the simple stuff.

My time online is too limited everyone else is improving, but I am standing still , sigh
Relying on two sheets of draft paper, I'll keep working hard...

[ Last edited by 523066680 on 2009-2-22 at 12:24 ]
Forum Jump: