Since none I could find worked the way I wanted them to, I decided to write my own version, with input an output as I like them to be.
They work under 2K/XP (no Dos/Win9x/Me sorry).
Enjoy.
jaclaz
Posted 04 September 2007 - 09:20 PM
Posted 05 October 2007 - 10:42 AM
W:\OFS\TOOLS>multiply 1024*1024
1048576
W:\OFS\TOOLS>multiply 1,024*1024
1,048,576
W:\OFS\TOOLS>multiply 1.024*1024
1.048.576
W:\OFS\TOOLS>multiply 1.024*1048576
1.073.741.824
W:\OFS\TOOLS>multiply 1.024*1.073.741.824
1.099.511.627.776
W:\OFS\TOOLS>multiply 1024*1024§
1§048§576
Posted 12 October 2007 - 04:10 PM
Jaclaz,Another pretty much useless batch , multiply.cmd.
The batch language can do Integer Math quite well, though all operations have a limit fixed to hex 7FFFFFF i.e. 2147483647 decimal.
Multiply.cmd takes two numbers and multiplies them, with precision up to 15 digits:
The first non numeric character found (exception made for "*") is interpreted as the thousands separator:
jaclaz
Posted 14 October 2007 - 10:55 AM
Jaclaz,
You are great
Until now I did not even have had the opinion, that somethig like this is possible by simple *.cmd!
Peter
Posted 01 December 2008 - 11:26 AM
Posted 29 March 2010 - 09:46 AM
Posted 01 September 2011 - 01:39 PM
@ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION ::======================================================== ::| WARNING! Limit is 2147483647 i.e. 7FFFFFF WARNING! | ::======================================================== :: dec2hex.cmd :: a simple and nice way to convert decimal numbers to hex numbers :: by jaclaz, thanks to "SmartGenius" findings on Dynamic Environment Variables :: and to Rob Van der Woude: http://www.robvanderwoude.com/ntset.php :input_loop SET Input_dec=NOTHING SET /P Input_dec=Input a positive decimal number smaller than 2147483648 : IF "%Input_dec%"=="NOTHING" GOTO :input_loop IF %Input_dec% geq 2147483647 ECHO WAAAAY TOO BIG....&GOTO :input_loop CALL :dec2hex VAR %Input_dec% SET VAR_ ECHO :check ECHO SET /A VAR=%VAR% SET /A VAR=%VAR% SET VAR GOTO :EOF :dec2hex ECHO %0 CMD /C EXIT /B %2 SET "%1=%=ExitCode%" SET %1=0x!%1! SET %1__full=!%1! SET %1_byte=0x!%1:~-2! SET %1_word=0x!%1:~-4! GOTO :EOF
@ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION ::======================================================== ::| WARNING! Limit is 2147483647 i.e. 7FFFFFF WARNING! | ::======================================================== :: chrs.cmd :: a simple and nice way to convert decimal numbers to ASCII characters :: by jaclaz, thanks to "SmartGenius" findings on Dynamic Environment Variables :: and to Rob Van der Woude: http://www.robvanderwoude.com/ntset.php :input_loop SET Input_dec=NOTHING SET /P Input_dec=Input a positive decimal number smaller than 256: IF "%Input_dec%"=="NOTHING" GOTO :input_loop IF %Input_dec% geq 256 ECHO WAAAAY TOO BIG....&GOTO :input_loop CALL :getchar VAR %Input_dec% ECHO %Input_dec% is ASCII character %VAR% GOTO :EOF :getchar ECHO %0 CMD /C EXIT /B %2 SET "%1=%=ExitCodeAscii%" GOTO :EOF
@ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION :: asciitable.cmd :: a simple and nice way to print an ASCII table of characters :: (only "ECHOable" characters) :: by jaclaz, thanks to "SmartGenius" findings on Dynamic Environment Variables :: and to Rob Van der Woude: http://www.robvanderwoude.com/ntset.php FOR /L %%A IN (32,1,126) DO ( CALL :getchar %%A ) GOTO :EOF :getchar CMD /C EXIT /B %1 SET "Line=%=ExitCode%" SET /A Line_Dec=0x%Line% SET "Line_hex=0x%Line:~-2% SET "Line_char=%=ExitCodeAscii%" ECHO %Line_dec% %Line_hex% "( %Line_char% )" GOTO :EOF
Posted 10 April 2014 - 02:55 PM
Posted 29 February 2016 - 02:44 PM
A new kid on the block (actually only a slight mod of multiply.cmd):
KMG2B.cmd : small batch file to convert numbers expressed in Kb, Mb, Gb into bytes, overcoming the 0x07FFFFFF limit in batch (aka 2,147,483,647) this is about "real" K/M/G, i.e. powers of 1024 what would be now called KiB, MiB, GiB. ******** Version 1.0 29 February 2016 ******** by jaclaz This file is licensed under my "CAREWARE" license: http://jaclaz.altervista.org/Projects/careware.html Usage: KMG2B.cmd Integer[K|M|G]
Wonko
Posted 20 August 2017 - 04:18 PM
Posted 23 August 2017 - 11:43 AM
Is B2KMG.cmd (small batch file to convert numbers expressed in bytes into Kb, Mb, Gb) also possible ?
Sure it is possible.
@ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION SET N=%1 :L SET R= FOR /L %%? IN (14,-1,1) DO ( SET P=!N:~0,%%?! IF !P!==%N% SET L=%%? ) SET C=0 FOR /L %%? IN (0,1,%L%) DO ( IF %%?==%L% GOTO :O SET /A D=10*!C!+!N:~%%?,1! SET /A V=!D!/2 SET /A C=!D!-!V!-!V! SET R=!R!!V! ) :O IF "0"=="!R:~0,1!" SET R=!R:~1! IF NOT DEFINED R SET R=0 SET /A I+=1 IF %I% EQU 10 ECHO %R% KB IF %I% EQU 20 ECHO %R% MB IF %I% EQU 30 ECHO %R% GB IF %I% LSS 30 SET N=%R%&GOTO :L
Still the whole idea of posting these little batches is that people can get inspired by this or that little trick and write his/her own batches.
Another approach:
@ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION SET K=%1 FOR /L %%K IN (0,1,9) DO SET K=!K:%%K=%%K ! CALL :B K CALL :B M CALL :B G GOTO :EOF :B SET M= FOR /L %%K IN (1,1,10) DO ( SET G= IF NOT "!K!"==" 0" CALL :K !K! ) SET M=!K: =! ECHO %M% %1B GOTO :EOF :K SET /A B=%G%%1/2 CALL :%1 SET M=%M% %B% IF "%M:~,3%"==" 0 " SET M=%M:~2% SHIFT IF NOT %1.==. GOTO :K SET K=!M!&&SET M= GOTO :EOF :M :0 :2 :4 :6 :8 SET G= GOTO :EOF :G :1 :3 :5 :7 :9 SET G=1 GOTO :EOF
Wonko
0 members, 1 guests, 0 anonymous users