Computing.Net > Forums > Disk Operating System > Batch: convert HEX to DEC and vice-versa

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch: convert HEX to DEC and vice-versa

Reply to Message Icon

Name: Secret_Doom
Date: April 23, 2002 at 15:14:40 Pacific
Comment:

Hi folks. I've once developed a batch script that would convert hexadecimal values to decimal values and vice-versa.

I've made a new version of it (2.0). The sintax is much simpler (it was kinda confusing at previous version), there is a much better error checking, which includes error checking for invalid numbers, and the
source is much more simpler. The converted number is saved into %num%. The speed didn't change too much. See timing below:

PIII-700Mhz RAM-128MB Windows 98 second edition
convert.bat FFFF h = 0.21 seconds
convert.bat 65535 d = 0.28 seconds

The maximum number to convert is FFFF h and 99999 d.
The source code is in the following URL:

http://www.batch.hpg.com.br/other/convert.txt

Comments are welcome. I hope anyone finds some use to this!

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br



Sponsored Link
Ads by Google

Response Number 1
Name: VP
Date: April 27, 2002 at 15:18:49 Pacific
Reply:

Now that's cool. I thought stuff like this was impossable.

Now is it be possable to add a input and a read from a file. Do conversion then write to a second file. ?

That would be really neat !

VP


0

Response Number 2
Name: Secret_Doom
Date: April 27, 2002 at 16:34:35 Pacific
Reply:

VP, do you mean adding two more ways of using the script, one would be to ask user the number and type of conversion, and the other would be get the number from a file, convert and store on an another file, is that it?

Well, that is pretty possible!

Anyway, be aware... I didn't make a *pure* conversion. Who actually does the real conversion is DEBUG.exe.

On the hex-dec conversion, I run a script like this:

Nfilename.ext
rcx
[n]
w
q

[n] is the number to be converted.
Then, I make a "dir filename.ext". The output from this has the file size, but in decimals. Then I just have to get the number out from the output.

The dex-hex conversion creates a file which size is the number to be converted. Then I run this script:

w
q

The output has the file size, in hexadecimals! Again, all what's left to do is extract the number from the output.

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 3
Name: VP
Date: April 30, 2002 at 03:27:27 Pacific
Reply:

Sorry, I did not make myself clear.
Input a file name
open file
Read a byte from file
Convert
Write converted to second file
Loop till EOF of first file.


0

Response Number 4
Name: Secret_Doom
Date: April 30, 2002 at 12:47:27 Pacific
Reply:

Yes, of course it's possible. Let's number the procedure:

1. Get user input (filename)
2. Get first line from filename to a variable
3. Convert variable
4. Write to a second file (hardcoded name?)

How to do all that:

1. http://www.batch.hpg.com.br/index.htm#07
2. http://www.batch.hpg.com.br/index.htm#15
3. convert.bat (run on a subroutine)
4. "echo %num%> output.ext"

Just put it all togeter! Of course, there should be some error checking between those procedures (e.g.: check if inputed filename exists)

Do you really need it or you're jusk asking if it's possible? If you want it, I can make for you, it won't cost be more that a few minutes.

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 5
Name: VP
Date: May 1, 2002 at 13:26:04 Pacific
Reply:

secret_doom,

That be a neat batch file to have.
But I can't think of anything to use
it in. So dont waste your time trying
to make it.

Thanks for the help and time.

VP


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch: convert HEX to DEC and vice-versa

can't open C: in DOS with XP www.computing.net/answers/dos/cant-open-c-in-dos-with-xp/9086.html

Automate batch files www.computing.net/answers/dos/automate-batch-files/4052.html

convert .bat to exe or com files???? www.computing.net/answers/dos/convert-bat-to-exe-or-com-files/10173.html