Stop the Hollyweb! No DRM in HTML5.

位运算Pascal相关函数/过程

Function Getlen(P:longint):longint;
var
 i:longint;
  begin
  getlen:=0;
  for i:=1 to 31 do
    begin
    if p and 1=1 then getlen:=i;
    p:=p shr 1;
  end;
end;

Function GetBit(Num,bit:longint):boolean;
  begin
  if (num and (1 shl(bit-1)))=0 then exit(false) else exit(true);
end;

Procedure changeBit(var num:longint;bit:longint;opt:boolean);
  begin
  if opt then
    num:=num or (1 shl (bit-1))
  else
    num:=num and not (1 shl (bit-1));
end;

Function getblock(num:longint;start,len:longint):longint;
var
 i,tmp:longint;
  begin
  tmp:=0;
  for i:=1 to len do
    tmp:=tmp or (1 shl (i-1));
  Getblock:=(num and (tmp shl (start-1))) shr (start-1);
end;

Procedure changeBlock(var num:longint;start,opt:longint);
var
 len,tmp,i:longint;
  begin
  len:=getlen(opt);
  tmp:=0;
  for i:=1 to len do
    begin
    tmp:=tmp or 1;
    tmp:=tmp shl 1;
  end;
  tmp:=not (tmp shl (start-1));
  num:=num and tmp;
  num:=num or (opt shl (start-1));
end;      

 

posted on 2012-03-22 20:07  灰天飞雁  阅读(530)  评论(0编辑  收藏  举报

填写您的邮件地址,订阅我们的精彩内容:  点击这里给我发消息

添加到收藏夹