能正确处理的最大数为2147483647,也就是31位2进制数,第32位就出错了,3742668 版主的那个版本也一样,输入2147483648就出错,虽然可以通过位移的次数来判断使精确度达到4294967295,但是我在应用上是碰不到这么大的数了,也就不多麻烦了。
@echo off
setlocal enabledelayedexpansion
set hexstr=0 1 2 3 4 5 6 7 8 9 A B C D E F
set d=0
for %%i in (%hexstr%) do (set d!d!=%%i&set/a d+=1)
set/p scanf=能正确处理的最大数为,请输入需要转换的十进制数:
if not defined scanf exit/b
set dec=%scanf%
call :d2h
if not defined hex set hex=0
echo %dec% 的十六进制为:0x%hex%
pause>nul
exit/b
:d2h
if %scanf% equ 0 exit/b
set/a tscanf=%scanf%"&"15
set/a scanf">>="4
set hex=!d%tscanf%!!hex!
goto :d2h
本帖最近评分记录
(共 4 条)
点击查看详情
| 评分人 | 分数 | 时间 |
|---|---|---|
| redtek | +5 | 2007-01-07 21:04 |
| lxmxn | +10 | 2007-01-08 04:28 |
| ccwan | +5 | 2007-01-12 06:57 |
| electronixtar | +20 | 2007-01-13 06:56 |
