i have trouble batch file
@echo off setlocal enableextensions enabledelayedexpansion set lookup=0123456789abcdef &set hexstr= set mac_b1=03 set mac_b2=5d set mac_b3=00 set mac_b4=00 set mac_b5=00 set mac_b6=00 set my_file=runningno.txt set runningno=128 setlocal enableextensions enabledelayedexpansion set lookup=0123456789abcdef &set /a hexstr= set /a a=%runningno% :loop set /a b=!a! %% 16 & set /a a=!a! / 16 set hexstr=!lookup:~%b%,1!%hexstr% if %a% gtr 0 goto :loop if %runningno% leq 255 ( set /a mac_b6 = %hexstr% ) echo mac address:%mac_b1%-%mac_b2%-%mac_b3%-%mac_b4%-%mac_b5%-%mac_b6% the output fine if runningno in hex without "abcdef"
03-5d-00-00-00-80 in other i.e set runningno=255 output should 03-5d-00-00-00-ff
03-5d-00-00-00-0 please help
@echo off setlocal enableextensions enabledelayedexpansion set "mac_b1=03" set "mac_b2=5d" set "mac_b3=00" set "mac_b4=00" set "mac_b5=00" set "mac_b6=00" set "runningno=128" set "lookup=0123456789abcdef" set /a "high=(runningno & 255) >> 4", "low=runningno & 15" set "mac_b6=!lookup:~%high%,1!!lookup:~%low%,1!" echo %mac_b1%-%mac_b2%-%mac_b3%-%mac_b4%-%mac_b5%-%mac_b6% edited seems value in runningno increase,
@echo off setlocal enableextensions enabledelayedexpansion set "mac_b1=03" set "mac_b2=5d" set "mac_b3=00" set "mac_b4=00" set "mac_b5=00" set "mac_b6=00" set "runningno=1458796" set "lookup=0123456789abcdef" set "value=%runningno%" /l %%a in (6, -1, 3) ( set /a "high=(value & 255) >> 4", "low=value & 15", "value>>=8" %%h in (!high!) %%l in (!low!) ( set "mac_b%%a=!lookup:~%%h,1!!lookup:~%%l,1!" ) ) echo %mac_b1%-%mac_b2%-%mac_b3%-%mac_b4%-%mac_b5%-%mac_b6% but has problem. arithmetics in batch files limited 32bit signed integers. means higher value can handled method 0x7fffff
Comments
Post a Comment