China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 22:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to use bitwise operations in set/a? View 7,270 Replies 42
Floor 31 Posted 2006-10-19 21:24 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Floor 32 Posted 2006-10-20 00:18 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
After calculating the encoded result after base64 conversion, it is also necessary to correspond to the relevant characters:


A ----------- 0
B ----------- 1
C ----------- 2
D ----------- 3
E ----------- 4
F ----------- 5
G ----------- 6
H ----------- 7
I ----------- 8
J ----------- 9
K ----------- 10
L ----------- 11
M ----------- 12
N ----------- 13
O ----------- 14
P ----------- 15
Q ----------- 16
R ----------- 17
S ----------- 18
T ----------- 19
U ----------- 20
V ----------- 21
W ----------- 22
X ----------- 23
Y ----------- 24
Z ----------- 25
a ----------- 26
b ----------- 27
c ----------- 28
d ----------- 29
e ----------- 30
f ----------- 31
g ----------- 32
h ----------- 33
i ----------- 34
j ----------- 35
k ----------- 36
l ----------- 37
m ----------- 38
n ----------- 39
o ----------- 40
p ----------- 41
q ----------- 42
r ----------- 43
s ----------- 44
t ----------- 45
u ----------- 46
v ----------- 47
w ----------- 48
x ----------- 49
y ----------- 50
z ----------- 51
0 ----------- 52
1 ----------- 53
2 ----------- 54
3 ----------- 55
4 ----------- 56
5 ----------- 57
6 ----------- 58
7 ----------- 59
8 ----------- 60
9 ----------- 61
+ ----------- 62
/ ----------- 63
Floor 33 Posted 2006-10-20 00:55 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
The time for all experts to show their skills has come.

Base64 encoding is quite useful, for example, in eml files, embedding bin in batch scripts, etc.

[ Last edited by electronixtar on 2006-10-20 at 01:08 ]

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'>"
Floor 34 Posted 2006-10-20 07:19 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 35 Posted 2006-10-20 10:32 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Originally posted by lxmxn at 2006-10-19 07:04:

  Thanks to brother est for writing the post about bit operations.

  But it didn't write out in which aspects these bit operations are applied, which can't arouse everyone's interest in bit operations. Everyone only knows vaguely...



This idea is good~ : )
Write some examples of bit operations that can arouse everyone's interest and are practical~ : )
It can both gather popularity, lay the foundation for development, and expand the knowledge scope~ : )
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 36 Posted 2006-10-20 21:57 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
To be honest, I just copied the bitwise operations from other languages and changed them to set /a. There's really nothing to write about.

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'>"
Floor 37 Posted 2007-08-19 11:53 ·  中国 湖南 怀化 电信
初级用户
Credits 25
Posts 19
Joined 2007-03-07 10:51
19-year member
UID 80997
Gender Male
Status Offline
Floor 38 Posted 2007-08-19 12:14 ·  中国 北京 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
//////
We are looking forward to it.
Floor 39 Posted 2007-08-22 23:30 ·  中国 湖南 长沙 电信
新手上路
Credits 7
Posts 3
Joined 2005-12-02 13:02
20-year member
UID 46335
Status Offline
Hehe, that really hits the nail on the head
Floor 40 Posted 2008-03-02 23:33 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Floor 41 Posted 2008-03-03 10:53 ·  中国 上海 黄浦区 电信
中级用户
★★
Credits 484
Posts 250
Joined 2007-06-05 23:33
19-year member
UID 90372
Gender Male
Status Offline
LZ, you need to first understand the conversion between decimal and binary, etc.

I'll give a few simple examples to explain bit operations under CMD:
set /a 13^<^<1
The result is 26, because the binary of 13 is 1101. Shifting left by 1 bit is equivalent to adding a 0 at the end of the binary, which is 11010, that is 26.
set /a 13^>^>1
The result is 6. Removing the last bit 1 from 1101 gives 110, which is 10 in decimal 6.

Similarly
set /a 13^<^<2 is 52
set /a 13^>^>2 is 3

Then talk about bitwise AND &
The meaning of bitwise AND is that after converting to binary, the bits are operated logically AND. The algorithm of AND operation is that it's 1 only if all are 1, otherwise 0.
set /a 13^&11
The result is 9
Because 1101&1011, there are 0s in the middle two bits. Only the first and last bits are both 1, so it's 1001, that is 10 in decimal 9.

After understanding that bit operations are bit-corresponding operations, there's no need to go into details about XOR and OR. Just say the algorithms of XOR and OR.

XOR is also called exclusive OR (there is also equivalence). The algorithm is that the result is 0 if two numbers are the same, and 1 if different, that is 0^1=1, 1^1=0, 0^0=0.
And the OR operation is that it's 0 only if all are 0, that is 0|1=1, 1|1=1, 0|0=0.
Floor 42 Posted 2009-04-23 12:42 ·  中国 福建 福州 电信
初级用户
Credits 20
Posts 18
Joined 2008-12-07 15:40
17-year member
UID 133147
Gender Male
From 浙江永康
Status Offline
@echo off
set b=0
for /l %%a in (1,1,100) do set /a b=b+%%a>>nul
echo The sum from 1 to 100 is: %b%
pause>nul
Experts:
What does "set /a a=00000010 << 2" mean?
Floor 43 Posted 2010-06-26 10:34 ·  中国 四川 成都 电信
新手上路
Credits 19
Posts 20
Joined 2010-05-09 20:11
16-year member
UID 166476
Gender Male
Status Offline
Forum Jump: