|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
 『楼 主』:
if 下的无效数字比较运算
使用 LLM 解释/回答一下
可以这样总结,无效的8进制或16进制数字比较运算时:
1,被比较字符串不含-:无效数字与不含-的字符串作比较运算时,进行字符比较。
2,被比较字符串仅第一个字符是-:如果无效数字与-后字符相同,则无效数字小。
3,被比较字符串含-,且为上面情况以外的时候,无效数字与脱掉所有-(允许脱掉所有-后为空)后的字符串作字符比较。
@echo off
if 0 GTR - (
if 0899 LSS 08990 echo OK1
if 0899 LSS -0899 echo OK2
if 0899 LSS 0--9 echo OK3
if 0899 LSS -0-9 echo OK4
if 0899 LSS ---- echo OK5
)
pause
我想,这个例子应该是最能说明无效数字比较运算时-被脱掉以及所有的-都被脱掉的问题。
Last edited by Hanyeguxing on 2009-10-6 at 20:03 ]
It can be summarized like this: when comparing invalid octal or hexadecimal numbers:
1. When the string to be compared does not contain "-": when comparing an invalid number with a string that does not contain "-", character comparison is performed.
2. When the first character of the string to be compared is only "-": if the invalid number is the same as the characters after "-", the invalid number is smaller.
3. When the string to be compared contains "-" and is not the above situation: compare the invalid number with the string obtained by removing all "-" (allowing the result after removing all "-" to be empty) character by character.
@echo off
if 0 GTR - (
if 0899 LSS 08990 echo OK1
if 0899 LSS -0899 echo OK2
if 0899 LSS 0--9 echo OK3
if 0899 LSS -0-9 echo OK4
if 0899 LSS ---- echo OK5
)
pause
I think this example should best illustrate the problem of "-" being removed and all "-" being removed during the comparison of invalid numbers.
Last edited by Hanyeguxing on 2009-10-6 at 20:03 ]
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2009-10-3 21:22 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
应该是不符合数字规则,就按字符串来较的,因为"-"在"0"之后,所以,08就小于-1了
It should be in violation of the digital rules, so it is compared as a string. Because "-" is after "0", so 08 is less than -1.
|

精简
=> 个人 网志  |
|
2009-10-3 23:25 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
if 08 gtr - echo 08大于-
if 08 lss -1 echo 08小于-1
但奇怪的是,08与-比较,0大于-;而08与-1比较,却0小于-。很是奇怪,不明白怎么会这样?
if 08 gtr - echo 08 greater than -
if 08 lss -1 echo 08 less than -1
But the strange thing is, when comparing 08 with -, 0 is greater than -; while comparing 08 with -1, 0 is less than -. It's very strange, I don't understand why this is happening?
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2009-10-4 12:04 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
当做字符串比较的时候
是从第一位开始比较,直到出现第一个不同的为止。
咦~ 楼上说的…… 莫非是一个当做数字,一个当做字符串了……
Last edited by 523066680 on 2009-10-4 at 19:09 ]
When comparing strings, it starts from the first character and goes until the first different one appears.
Hey~ What the person above said... Could it be that one is treated as a number and the other as a string...
Last edited by 523066680 on 2009-10-4 at 19:09 ]
|

综合型编程论坛
我的作品索引 |
|
2009-10-4 19:06 |
|
|
wxcute
中级用户
  
积分 458
发帖 211
注册 2006-7-26
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
不错的发现,CMD 看来不是一般的难理解。
A good discovery. It seems that CMD is not generally easy to understand.
|

┌───────┐
├→学习→实践→┤
└───────┘ |
|
2009-10-4 19:10 |
|
|
plp626
银牌会员
     钻石会员
积分 2278
发帖 1020
注册 2007-11-19
状态 离线
|
|
2009-10-6 00:06 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
有时间就多看看帮助
Numeric values are decimal numbers, unless
prefixed by 0x for hexadecimal numbers, and 0 for octal numbers.
So 0x12 is the same as 18 is the same as 022. Please note that the octal
notation can be confusing: 08 and 09 are not valid numbers because 8 and
9 are not valid octal digits.
有时间就多看看帮助
Numeric values are decimal numbers, unless
prefixed by 0x for hexadecimal numbers, and 0 for octal numbers.
So 0x12 is the same as 18 is the same as 022. Please note that the octal
notation can be confusing: 08 and 09 are not valid numbers because 8 and
9 are not valid octal digits.
|

 |
|
2009-10-6 09:31 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by HAT at 2009-10-6 09:31:
有时间就多看看帮助
Numeric values are decimal numbers, unless
prefixed by 0x for hexadecimal numbers, and 0 for octal numbers.
So 0x12 is the same as 18 is the same as 022. Please note that the octal
notation can be confusing: 08 and 09 are not valid numbers because 8 and
9 are not valid octal digits.
我知道08不是合法数字,但在 if 下是可以按字符进行比较的。只是在与-和-0比较时有问题
Originally posted by HAT at 2009-10-6 09:31:
Read the help more when you have time.
Numeric values are decimal numbers, unless
prefixed by 0x for hexadecimal numbers, and 0 for octal numbers.
So 0x12 is the same as 18 is the same as 022. Please note that the octal
notation can be confusing: 08 and 09 are not valid numbers because 8 and
9 are not valid octal digits.
I know that 08 is not a legal number, but under if, it can be compared character-wise. It's just that there are problems when comparing with - and -0.
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2009-10-6 10:03 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
|
2009-10-6 13:06 |
|
|
plp626
银牌会员
     钻石会员
积分 2278
发帖 1020
注册 2007-11-19
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by Hanyeguxing at 2009-10-4 12:04 PM:
if 08 gtr - echo 08大于-
if 08 lss -1 echo 08小于-1
但奇怪的是,08与-比较,0大于-;而08与-1比较,却0小于-。很是奇怪,不明白怎么会这样?
不好意思,我楼上的帖子没有针对楼主的这个疑问,我现在刚看到。
也许是bug。。。
Originally posted by Hanyeguxing at 2009-10-4 12:04 PM:
if 08 gtr - echo 08 greater than -
if 08 lss -1 echo 08 less than -1
But strangely, when comparing 08 with -, 0 is greater than -; but when comparing 08 with -1, 0 is less than -. It's very strange, I don't understand why this is the case?
Sorry, my previous post didn't address the owner's question, I just saw it now.
Maybe it's a bug...
|

山外有山,人外有人;低调做人,努力做事。
进入网盘(各种工具)~~ 空间~~cmd学习 |
|
2009-10-6 13:41 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
|
2009-10-6 13:50 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by netbenton at 2009-10-6 13:06:
试出来了!
if 08 lss -1 echo 08小于-1
这种情况应该是按字符串比较的,只是-1中的"-"号被丢弃了,
“-”号后的字符如果比0大则大
if 08 lss ...
我认为IF是取位比较的。
大家可以使用下面的IF语句试下:
if 08 lss -0# echo 08小于-#
if 008 lss -07 echo 08小于-07
if 8 lss -09 echo 08小于-09
pause
然后在测试下面的:
if 08#0 lss -9#0 echo 08小于-#
if 008 lss -07 echo 08小于-07
if 8 lss -09 echo 08小于-09
pause
以下是我做的分析:
当IF遇到同时包含数字和字符的字符串比较大小时, 由于无法比较大小,就同时向后移位取数比较,取代了原先的那位,就像SHIFT命令那样,取参!直到取到都是数字时,才做比较。大者为大。
Originally posted by netbenton at 2009-10-6 13:06:
Got it!
if 08 lss -1 echo 08 is less than -1
This situation should be a string comparison. Only the "-" sign in -1 is discarded. If the characters after "-" are larger than 0, it is larger.
if 08 lss ...
I think IF is bit comparison.
You can use the following IF statements to test:
if 08 lss -0# echo 08 is less than -#
if 008 lss -07 echo 08 is less than -07
if 8 lss -09 echo 08 is less than -09
pause
Then test the following:
if 08#0 lss -9#0 echo 08 is less than -#
if 008 lss -07 echo 08 is less than -07
if 8 lss -09 echo 08 is less than -09
pause
The following is my analysis:
When IF encounters a string comparison of both numbers and characters for size, because it cannot compare the size, it shifts backward at the same time to take numbers for comparison, replacing the original bit, just like the SHIFT command, taking parameters! It continues until all are numbers, then makes the comparison. The larger one is larger.
|

Discuz! 现在时间 |
|
2010-4-22 20:52 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
|
2010-4-22 21:01 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by gool123456 at 2010-4-22 20:52:
以下是我做的分析:
当IF遇到同时包含数字和字符的字符串比较大小时,由于无法比较大小,就同时向后移位取数比较,取代了原先的那位,就像SHIFT命令那样,取参!直到取到都是数字时,才做比较。大者为大。 ...
if a1 equ b1 echo.一样吗
Originally posted by gool123456 at 2010-4-22 20:52:
The following is my analysis:
When IF encounters a string comparison of numbers and characters at the same time, since it cannot compare the size, it shifts backward at the same time to take numbers for comparison, replacing the original bit, just like the SHIFT command, taking parameters! Until both are numbers, then compare. The larger one is larger....
if a1 equ b1 echo.一样吗
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-4-22 21:02 |
|
|
gool123456
初级用户
 
积分 89
发帖 76
注册 2009-12-13
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
if 的EQU应该是做字符串比较的 大小就不同了。
The EQU of if should be for string comparison, and the sizes are different.
|

Discuz! 现在时间 |
|
2010-4-22 21:19 |
|