hex batch

July 26, 2011 at 14:28:14
Specs: Windows XP
@echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
for /f "tokens=* delims= " %%a in (input.txt) do (
set /a c=%%a)
set LOOKUP=0123456789abcdef &set HEXSTR=&set PREFIX=
set /a A=%c%
:loop
if %A%=="" echo 0&goto :EOF
if !A! LSS 0 set /a A=0xfffffff + !A! + 1 & set PREFIX=f
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%>>output.txt
endlocal
)
input file
55
66
77
etc

hi all,
Ive been tinkering with this to try and get a batch process going. so far just last number gets converted.
The for loop at the mo won't work outside its current brackets any advice is welcome thanks.


See More: hex batch

Report •


#1
July 26, 2011 at 23:58:08
What about:

rem **** This uses the undocumented system variable "=exitcode" ****
@echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
for /f "tokens=* delims= " %%a in (input.txt) do (
    cmd /c exit /b %%a
    echo if the first digit is greater than 7, the number is negative 
    echo !=exitcode!
)


Report •

#2
July 30, 2011 at 16:52:27
Lol soz mate i thought you had answered the wrong question lol anyways nice trick how could i trim to just hex? no zero's. Or get the troublesome for/f working, it seems to be to do with the set c although ive changed mine a bit from the above.
Anyways feedback would be cool.

Report •

#3
July 30, 2011 at 17:29:23
Or get the troublesome for/f working, it seems to be to do with the set c although ive changed mine a bit from the above.

The way you were setting the variable meant that you would only get the very last line from the file, it's much easier to use the loop to your advantage.

Trimmed zero's:

rem **** This uses the undocumented system variable "=exitcode" ****
@echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
for /f "tokens=* delims= " %%a in (input.txt) do (
    cmd /c exit /b %%a
    for /f "tokens=1* delims=0" %%b in ("A0!=exitcode!") do (
        if "%%c"=="" (set hex=0) else set hex=%%c
    )
    echo !hex!
)
pause


Report •

Related Solutions

#4
July 30, 2011 at 18:27:10
Nice when i get time i will give your example a thorough looking over. Just out of curiosity is the way i tried, in a round about way possible. I presume so as you quoted "The way you were setting the variable meant that you would only get the very last line from the file".

Report •

#5
July 31, 2011 at 23:44:17
Just out of curiosity is the way i tried, in a round about way possible.

Yeah it's sort of possible, either by using "call" on a label and passing a parameter to it (you have to be careful about exit points) or setting a pseudo-array of variables(very inefficient and can be troublesome).

The main problem with what you were doing was the for loop, it set each value in the text file to the variable, every time overwriting it's previous value. The variable only contained the very last value in the file after the for loop finished executing.


Report •

#6
August 1, 2011 at 09:01:11
No problems judago i'm gona get bizy on some of this stuff, but if i have some problems i will post or maybe give you a shout.

Report •

Ask Question