中国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-05 22:22
48,039 topics / 350,124 posts / today 2 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Decimal to Hexadecimal (Bit Manipulation Version)
Printable Version  3,731 / 12
Floor1 0401 Posted 2007-01-07 06:23
中级用户 Posts 88 Credits 435
The maximum number that can be correctly processed is 2147483647, which is a 31-bit binary number. An error occurs at the 32nd bit. The version of moderator 3742668 is the same. Entering 2147483648 causes an error. Although the precision can reach 4294967295 by judging the number of shifts, I don't encounter such a large number in application, so I won't bother much.

Floor2 0401 Posted 2007-01-07 06:24
中级用户 Posts 88 Credits 435
==Deleted==

[ Last edited by 0401 on 2007-1-25 at 09:19 AM ]
Floor3 electronixtar Posted 2007-01-07 08:46
铂金会员 Posts 2,672 Credits 7,493
Floor4 0401 Posted 2007-01-07 09:24
中级用户 Posts 88 Credits 435
Originally posted by electronixtar at 2007-1-7 08:46:
The building owner is a strong person

I'm a noob, and I'm shy.
Post another decimal to binary conversion using the same method.
Floor5 lxmxn Posted 2007-01-07 17:15
版主 Posts 4,938 Credits 11,386

  A great person.
Floor6 redtek Posted 2007-01-07 21:04
金牌会员 Posts 1,147 Credits 2,902
Super top! Appreciate ~~ : )
Floor7 vlanmaster Posted 2007-01-12 06:55
初级用户 Posts 46 Credits 100
It's really refreshing to use, amazing.
Floor8 ccwan Posted 2007-01-12 06:57
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
That's really amazing. I'm supporting it.
Floor9 vkill Posted 2007-03-13 07:50
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Brother 0401 on the 4th floor, the decimal to binary conversion can still be improved. The tag :cut0 at the end is redundant. It's better to be like this:


:d2b
set a=1
for /l %%i in (1,1,31) do (
set/a t=%scanf%"&"!a!
set/a a*=2
if !t! equ 0 (set bin=0!bin!) else (set bin=1!bin!)
if %scanf% lss !a! exit/b
)
if %bin% equ 0 set bin=0 & goto :eof


Modifications are as follows:
1: 1,1,30 is changed because for /l %%i in (1,1,31) do (set/a a*=a) will already have an error.
2: Added a line if %scanf% lss !a! exit/b, because the operation of number a and a larger number is always 0. Since this is the case, it's better to directly end with if %scanf% lss !a! exit/b, and then the preceding 0s won't be removed later.
Floor10 xycoordinate Posted 2007-03-13 08:22
中级用户 Posts 228 Credits 493 From 安徽
Add a "stamp" first, otherwise it won't be found next time!
Floor11 genteman Posted 2007-11-02 12:44
初级用户 Posts 43 Credits 90
I will reply to post 9

if %scanf% lss !a! exit/b
There are obvious drawbacks in your code.
Every time the loop is executed, a judgment is made, which reduces the program efficiency
Floor12 genteman Posted 2007-11-02 12:57
初级用户 Posts 43 Credits 90
There is another question
"1,1,30 Because you for /l %%i in (1,1,31) do (set/a a*=a) has already gone wrong"

When %%i = 31 here, a = 2^(30), there is no mistake. It will be wrong when %%i = 32, at this time a = 2^(31)

So the code on floor 9 is correct!
Floor13 ZJHJ Posted 2010-08-10 09:03
高级用户 Posts 374 Credits 609
I used the method of remainder to write a decimal to hexadecimal conversion, and confirmed that the maximum limit processing is indeed 2147483647, that is, the hexadecimal limit is 7FFFFFFF, and the reversal also illustrates this problem. It should be said to be the limit of CMD.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023