中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-09 03:14
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » Conversion from decimal to hexadecimal:
Printable Version  2,120 / 13
Floor1 bat-zw Posted 2008-07-05 13:19
金牌会员 Posts 1,276 Credits 3,105
```
@echo off
set code=0123456789abcdef
:enter
cls&set /p num=Please enter a decimal number:
echo %num%|findstr ""&&goto enter
set var=%num%
:again
set /a ws=%var%%%16
call,set ws=%%code:~%ws%,1%%
set /a var/=16
set str=%ws%%str%
if %var% geq 16 goto again
cls&echo The decimal number %num% is converted to hexadecimal as: %var%%str%
pause>nul
```

[ Last edited by zw19750516 on 2008-7-5 at 01:50 PM ]
Floor2 HAT Posted 2008-07-05 13:39
版主 Posts 5,017 Credits 9,023
Previously saw others write

Floor3 pusofalse Posted 2008-07-05 14:04
银牌会员 Posts 646 Credits 1,604
Originally posted by zw19750516 at 2008-7-5 01:19 PM:
Floor4 hackerscans Posted 2008-07-05 14:19
初级用户 Posts 51 Credits 73
Strongly learn from the各位 upstairs.

(注:原句“强烈的向楼上各位学习。”中“强烈的”表述有误,应为“强烈地”,正确翻译为“Strongly learn from the各位 upstairs.” 但根据要求要保留原文错误的话就按错误的翻译,不过更准确的应该是“Strongly learn from everyone upstairs.”)
Floor5 bat-zw Posted 2008-07-05 14:23
金牌会员 Posts 1,276 Credits 3,105
```
@echo off
set code=1 2 3 4 5 6 7 8 9 a b c d e f&set m=1
set /p str=Please enter a hexadecimal number:
:lp
set a=%str:~-1%
for %%i in (%code%) do set /a n+=1&if "%%i" equ "%a%" call,set a=%%n%%
set /a num+=m*a
set /a m*=16,n=0
if defined str set str=%str:~,-1%&goto lp
echo %num%&pause>nul


[ Last edited by zw19750516 on 2008-7-5 at 02:25 PM ]
```
Floor6 26933062 Posted 2008-07-05 14:42
银牌会员 Posts 879 Credits 2,268
Hexadecimal to decimal: There is a simpler way.
Floor7 pusofalse Posted 2008-07-05 14:45
银牌会员 Posts 646 Credits 1,604
Hexadecimal to decimal. I know a very simple method, which I learned from the post about getting ASCII codes I saw yesterday...

set/p num=
set/a a=0x%num%
echo %a%
pause
Floor8 bat-zw Posted 2008-07-05 15:07
金牌会员 Posts 1,276 Credits 3,105
Originally posted by 26933062 at 2008-7-5 14:42:
Hexadecimal to decimal: There is a simpler method.

I just realized it's so simple. It seems that learning is endless.
Floor9 HAT Posted 2008-07-05 15:58
版主 Posts 5,017 Credits 9,023
rem Three different data inputs, but all will be output in decimal.
rem Decimal
set /a 123
rem Octal
set /a 012
rem Hexadecimal
set /a 0xa
Floor10 zh159 Posted 2008-07-06 00:03
金牌会员 Posts 1,467 Credits 3,687
The conversion between number bases has actually been discussed before.
Floor11 terse Posted 2008-07-06 17:02
银牌会员 Posts 946 Credits 2,404
It seems that there was one posted before. Adding a variable can realize decimal to any base conversion.
Floor12 HAT Posted 2008-07-06 19:25
版主 Posts 5,017 Credits 9,023
Originally posted by terse at 2008-7-6 05:02 PM:
It seems that it was posted before
Adding a variable can realize decimal to any base conversion


The code at that time
Floor13 ywwywwjm Posted 2008-07-08 01:51
初级用户 Posts 13 Credits 42
echo ibase=10;obase=16;10|bc
Floor14 HAT Posted 2008-07-08 02:17
版主 Posts 5,017 Credits 9,023
```
printf "%x" "10"
```

printf.exe
http://upload.cn-dos.net/img/580.zip
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023