我程序中的一段, var i,j,k:integer; begin i:=12; j:=i shr 2 ;//右移两位 k:=j and $3; if k<>0 then begin if k=1 then showmessage('1') else if k=2 then showmessage('2') else SHOWMESSAGE('ERROR'); end end; 记得给分呀!!!
and 如判断第n位方法 function UseBitAnd(i,n:integer):integer; var m,j:integer; begin if n<3 then m:=n; for j:=3 to n do m:=m*2; result:=i and m; end;
先左移位,再右移位. 如要判断Byte(共8位)第五位 左移3右称7,最后得到的就是此位的值
pascal 位操作也用 or 和 and 就行A and $01判断 A的第0位是否为1
var i, j, h: byte; r : array[1..8] of integer; begin h := 255; j := 1; for i := 1 to 8 do begin if (h and j)>0 then r[i]:=1 else r[i] := 0; j := j shl 1; end; end; 最后,数组中应该是结果。
var i,j,k:integer;
begin
i:=12;
j:=i shr 2 ;//右移两位
k:=j and $3;
if k<>0 then
begin
if k=1 then showmessage('1') else
if k=2 then showmessage('2') else SHOWMESSAGE('ERROR');
end
end;
记得给分呀!!!
如判断第n位方法
function UseBitAnd(i,n:integer):integer;
var
m,j:integer;
begin
if n<3 then
m:=n;
for j:=3 to n do
m:=m*2;
result:=i and m;
end;
如要判断Byte(共8位)第五位
左移3右称7,最后得到的就是此位的值
i, j, h: byte;
r : array[1..8] of integer;
begin
h := 255;
j := 1;
for i := 1 to 8 do
begin
if (h and j)>0 then
r[i]:=1
else
r[i] := 0;
j := j shl 1;
end;
end;
最后,数组中应该是结果。
and/or/xor/not:与或非异或
$ff:十六进制数据