|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『楼 主』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-10-17 23:11:
有意思, qwe1234567版主第一楼取余数时忘记了cmd和批处理下"%"与"%%"号的差别.
输入行太长, 这可能是因为系统为环境变量分配的内存空頮..
这能怪我吗,也是微软没有说清楚SET/A的用法,就SET /A相信大家多不会使用所有的被评估的数字表达式吧,就下面的你会多少?
() - 分组
* / % - 算数运算符
+ - - 算数运算符
<< >> - 逻辑移位
- 按位“与”
^ - 按位“异”
| - 按位“或”
= *= /= %= += -= - 赋值
&= ^= |= <<= >>=
, - 表达式分隔符
我想除了* / %+ - = *= /= %= += -= -会用,其他的都不会用吧,呵呵!
Originally posted by pengfei at 2006-10-17 23:11:
Interesting, the first post by moderator qwe1234567 forgot the difference between "%" and "%%" in cmd and batch processing when taking the remainder.
The input line is too long, this may be because the system has insufficient memory allocated for environment variables..
Can this be blamed on me? It's also because Microsoft didn't explain the usage of SET/A clearly. Just SET /A, I believe everyone doesn't know how to use all the evaluated numeric expressions. How many of the following do you know?
() - Grouping
* / % - Arithmetic operators
+ - - Arithmetic operators
<< >> - Logical shift
- Bitwise "AND"
^ - Bitwise "XOR"
| - Bitwise "OR"
= *= /= %= += -= - Assignment
&= ^= |= <<= >>=
, - Expression separator
I think except for * / %+ - = *= /= %= += -= - which can be used, the others are not used. Hehe!
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-10-18 03:19 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
其他的都是位运算。学过C的都知道
The rest are bitwise operations. Those who have studied C all know that
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-10-18 04:31 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-10-18 19:54 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
C语言里的教程,如果还是没有搞懂的话,我可以考虑写一个bat的示例。位运算是计算机比较本质的运算,特点是效率高,缺点是不好用,呵呵
位运算
前面介绍的各种运算都是以字节作为最基本位进行的。 但在很多系统程序中常要求在位(bit)一级进行运算或处理。C语言提供了位运算的功能, 这使得C语言也能像汇编语言一样用来编写系统程序。
一、位运算符C语言提供了六种位运算符:
& 按位与
| 按位或
^ 按位异或
~ 取反
<< 左移
>> 右移
1. 按位与运算 按位与运算符"&"是双目运算符。其功能是参与运算的两数各对应的二进位相与。只有对应的两个二进位均为1时,结果位才为1 ,否则为0。参与运算的数以补码方式出现。
例如:9&5可写算式如下: 00001001 (9的二进制补码)&00000101 (5的二进制补码) 00000001 (1的二进制补码)可见9&5=1。
按位与运算通常用来对某些位清0或保留某些位。例如把a 的高八位清 0 , 保留低八位, 可作 a&255 运算 ( 255 的二进制数为0000000011111111)。
main(){
int a=9,b=5,c;
c=a&b;
printf("a=%d\nb=%d\nc=%d\n",a,b,c);
}
2. 按位或运算 按位或运算符“|”是双目运算符。其功能是参与运算的两数各对应的二进位相或。只要对应的二个二进位有一个为1时,结果位就为1。参与运算的两个数均以补码出现。
例如:9|5可写算式如下:
00001001|00000101
00001101 (十进制为13)可见9|5=13
main(){
int a=9,b=5,c;
c=a|b;
printf("a=%d\nb=%d\nc=%d\n",a,b,c);
}
3. 按位异或运算 按位异或运算符“^”是双目运算符。其功能是参与运算的两数各对应的二进位相异或,当两对应的二进位相异时,结果为1。参与运算数仍以补码出现,例如9^5可写成算式如下:
00001001^00000101 00001100 (十进制为12)
main(){
int a=9;
a=a^15;
printf("a=%d\n",a);
}
4. 求反运算 求反运算符~为单目运算符,具有右结合性。 其功能是对参与运算的数的各二进位按位求反。例如~9的运算为: ~(0000000000001001)结果为:1111111111110110
5. 左移运算 左移运算符“<<”是双目运算符。其功能把“<< ”左边的运算数的各二进位全部左移若干位,由“<<”右边的数指定移动的位数,
高位丢弃,低位补0。例如: a<<4 指把a的各二进位向左移动4位。如a=00000011(十进制3),左移4位后为00110000(十进制48)。6. 右移运算 右移运算符“>>”是双目运算符。其功能是把“>> ”左边的运算数的各二进位全部右移若干位,“>>”右边的数指定移动的位数。
例如:设 a=15,a>>2 表示把000001111右移为00000011(十进制3)。 应该说明的是,对于有符号数,在右移时,符号位将随同移动。当为正数时, 最高位补0,而为负数时,符号位为1,最高位是补0或是补1 取决于编译系统的规定。Turbo C和很多系统规定为补1。
main(){
unsigned a,b;
printf("input a number: ");
scanf("%d",&a);
b=a>>5;
b=b&15;
printf("a=%d\tb=%d\n",a,b);
}
请再看一例!
main(){
char a='a',b='b';
int p,c,d;
p=a;
p=(p<<8)|b;
d=p&0xff;
c=(p&0xff00)>>8;
printf("a=%d\nb=%d\nc=%d\nd=%d\n",a,b,c,d);
}
Last edited by electronixtar on 2006-10-18 at 22:06 ]
Tutorials in C language. If you still don't understand, I can consider writing a bat example. Bitwise operations are relatively fundamental operations in computers, characterized by high efficiency, but the disadvantage is that they are not easy to use, heh heh
Bitwise Operations
The various operations introduced earlier are all performed at the byte as the most basic bit. But in many system programs, operations or processing at the bit (bit) level are often required. The C language provides bitwise operation functions, which enables the C language to be used to write system programs like assembly language.
1. Bitwise Operators The C language provides six bitwise operators:
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Ones' complement
<< Left shift
>> Right shift
1. Bitwise AND Operation The bitwise AND operator "&" is a binary operator. Its function is that the corresponding binary bits of the two numbers involved in the operation are ANDed. Only when the corresponding two binary bits are both 1, the result bit is 1; otherwise, it is 0. The numbers involved in the operation appear in two's complement form.
For example: 9&5 can be written as the following formula: 00001001 (binary two's complement of 9) & 00000101 (binary two's complement of 5) 00000001 (binary two's complement of 1) It can be seen that 9&5=1.
Bitwise AND operation is usually used to clear certain bits to 0 or retain certain bits. For example, to clear the high eight bits of a to 0 and retain the low eight bits, you can perform a&255 operation (the binary number of 255 is 0000000011111111).
main(){
int a=9,b=5,c;
c=a&b;
printf("a=%d\nb=%d\nc=%d\n",a,b,c);
}
2. Bitwise OR Operation The bitwise OR operator "|" is a binary operator. Its function is that the corresponding binary bits of the two numbers involved in the operation are ORed. As long as one of the corresponding two binary bits is 1, the result bit is 1. The two numbers involved in the operation both appear in two's complement form.
For example: 9|5 can be written as the following formula:
00001001|00000101
00001101 (decimal is 13) It can be seen that 9|5=13
main(){
int a=9,b=5,c;
c=a|b;
printf("a=%d\nb=%d\nc=%d\n",a,b,c);
}
3. Bitwise XOR Operation The bitwise XOR operator "^" is a binary operator. Its function is that the corresponding binary bits of the two numbers involved in the operation are XORed. When the corresponding two binary bits are different, the result is 1. The numbers involved in the operation still appear in two's complement form. For example, 9^5 can be written as the following formula:
00001001^00000101 00001100 (decimal is 12)
main(){
int a=9;
a=a^15;
printf("a=%d\n",a);
}
4. Ones' Complement Operation The ones' complement operator ~ is a unary operator with right associativity. Its function is to invert the binary bits of the number involved in the operation. For example, the operation of ~9 is: ~(0000000000001001) The result is: 1111111111110110
5. Left Shift Operation The left shift operator "<<" is a binary operator. Its function is to shift all the binary bits of the operand on the left of "<<" to the left by several bits, and the number on the right of "<<" specifies the number of bits to move.
High bits are discarded, and low bits are filled with 0. For example: a<<4 means shifting all the binary bits of a to the left by 4 bits. If a=00000011 (decimal 3), after shifting left by 4 bits, it is 00110000 (decimal 48). 6. Right Shift Operation The right shift operator ">>" is a binary operator. Its function is to shift all the binary bits of the operand on the left of ">>" to the right by several bits, and the number on the right of ">>" specifies the number of bits to move.
For example: Let a=15, a>>2 means shifting 000001111 to the right to get 00000011 (decimal 3). It should be noted that for signed numbers, the sign bit will move along when shifting to the right. When it is a positive number, the highest bit is filled with 0, and when it is a negative number, the sign bit is 1. Whether the highest bit is filled with 0 or 1 depends on the regulations of the compilation system. Turbo C and many systems specify that it is filled with 1.
main(){
unsigned a,b;
printf("input a number: ");
scanf("%d",&a);
b=a>>5;
b=b&15;
printf("a=%d\tb=%d\n",a,b);
}
Please take another example!
main(){
char a='a',b='b';
int p,c,d;
p=a;
p=(p<<8)|b;
d=p&0xff;
c=(p&0xff00)>>8;
printf("a=%d\nb=%d\nc=%d\nd=%d\n",a,b,c,d);
}
Last edited by electronixtar on 2006-10-18 at 22:06 ]
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-10-18 21:59 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-10-18 22:01 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
electronixtar懒得写,哈哈……
electronixtar is too lazy to write, haha...
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-18 22:24 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
很多教程(多数教程)上写的位运算(几乎)都象是教科方式的灌输找不到让人激动地方:)
就象学生时代学习数学一样,除了几何还能让人知道这东东做什么用以外,
象是什么微机分等等一大堆看着想自杀的内容,书上并没有说这些东东的实用性,
可是到了财务分析应用的时候,这些还都是必须的,等这时候再看公式早TMD忘了:)
很多课程教育太死板~:)
Many tutorials (most tutorials) write about bit operations (almost) like textbook-style indoctrination, and there's no exciting place to be found : )
Just like when learning mathematics during student days, except for geometry where you can know what this thing is used for, things like a bunch of micro-calculus and so on that make you want to commit suicide. The book doesn't say the practicality of these things. But when it comes to financial analysis applications, these are all necessary. By then, I've long forgotten the formulas : )
Many course educations are too rigid ~ : )
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-18 22:30 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
……个人认为 cmd 下的和 C 里面的运算没什么区别。
electronixtar懒得写,哈哈……
…………………………不要逼我写…………………………-_-!
Last edited by electronixtar on 2006-10-18 at 22:35 ]
……Personally, there's not much difference between the operations in cmd and in C.
electronixtar is too lazy to write, haha……
…………………………Don't force me to write…………………………-_-!
Last edited by electronixtar on 2006-10-18 at 22:35 ]
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-10-18 22:30 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
哈哈……同意~:)
Haha... Agreed~ :)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-18 22:36 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
有几个真的不会用,有空就写几个吧。 = =b
There are a few that really don't know how to use. I'll write a few when I have time. = =b
|
|
2006-10-18 22:38 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
建议electronixtar兄现在就新开一个关于讨论批处理位运算的专贴:)
It is suggested that brother electronixtar start a new special thread to discuss batch processing bitwise operations right now : )
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-18 22:43 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
这些符号的运用大家都会用,书上等都说得很清楚:)
不过,我非常不喜欢书上或教科书上的教学方式,
它并不能让人一眼看到位运算的课程就立即产生那种使人着迷、废寝忘食、疯狂和一定要现在就试试的想法……
所以,这是教学方式的失败!
应该是这样的,看完之后练习之后……
“噢,原来是这样!”
“天哪!在没看到这篇教程以前,我居然走了10年的弯路!!!”
“啊!原来位运算这么神奇,它可还可以做五字棋等游戏的智能运算……”
等等……
我最不喜欢教科书上说的,一大堆运算就是不说明这些计算在现实生活中和编程中的应用启发……
Everyone knows how to use these symbols, and books explain them clearly : )
However, I really dislike the teaching methods in books or textbooks,
It can't make people immediately have that fascinated, forget to eat and sleep, crazy and must try now idea when seeing the bitwise operation course...
So, this is the failure of the teaching method!
It should be like this, after reading and practicing...
"Oh, so that's how it is!"
"Oh my god! Before I saw this tutorial, I actually took 10 years of detours!!!"
"Oh! Bitwise operations are so amazing, they can also be used for intelligent operations in games like five-in-a-row..."
Wait...
What I dislike most about textbooks is that a large number of operations just don't explain the application inspirations of these calculations in real life and programming...
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-18 22:48 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by electronixtar at 2006-10-18 22:30:
……个人认为 cmd 下的和 C 里面的运算没什么区别。
…………………………不要逼我写…………………………-_-!
那你就写个纯CMD下的位运算来我们看看!我还真要逼你写,呵呵,相信大家都希望看到CMD下的位运算吧。
Originally posted by electronixtar at 2006-10-18 22:30:
……Personally, I think there is no difference between the operations in cmd and in C.
…………………………Don't force me to write…………………………-_-!
Then you write a pure bit operation in CMD for us to see! I really want to force you to write, hehe, I believe everyone wants to see the bit operation in CMD.
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-10-18 22:52 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
这个……你们够~~
This……You guys are enough~~
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-10-18 22:53 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
写吧,我们期待着。
PS:插句题外话,为何我刷新时,经常会刷到别的帖子,过会儿,又会刷回这帖,怪事,而且碰到不止一次了。
Go ahead, we're looking forward to it.
PS: By the way, why do I often see other posts when I refresh, and then it comes back to this post after a while? It's strange, and I've encountered this more than once.
|
|
2006-10-18 22:55 |
|
|