My aim is to create a random hexadecimal number that looks like 02xxxxxxxxxx with a batch file. But I habe problems by passing the single digit number between different batch files.
top.bat
for /f %%i in ('ran') do set b0=%%i
echo %b0%
ran.bat
@echo off
SET /a A=%RANDOM%*16/32768
for /f %%i in ('tohex.bat A') do set a0=%%i
echo %a0%
tohex.bat
@echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set LOOKUP=0123456789abcdef &set HEXSTR=&set PREFIX=
if "%1"=="" echo 0&goto :EOF
set /a A=%*
if !A! LSS 0 set /a A=0xfffffff + !A! + 1 & set PREFIX=f
:loop
set /a B=!A! %% 16 & set /a A=!A! / 16
set HEXSTR=!LOOKUP:~%B%,1!%HEXSTR%
if %A% GTR 0 goto :loop
echo %PREFIX%%HEXSTR%
Aucun commentaire:
Enregistrer un commentaire