获取字节中的bit值

procedure getBits(aByte:Byte; bitArr: array of Byte);
asm
  mov ecx,0
  @@1:
  shr al,1
  jnc @@2
  mov [edx],1
  @@2:
  inc cx
  inc edx
  cmp ecx,8
  jnz @@1
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  aByte: Byte;
  bitArr: array [0..7] of Byte;
begin
  aByte := $0F;
  ZeroMemory(@bitArr,SizeOf(bitArr));
  getBits(aByte,bitArr);
  for i := 0 to 7 do
    if bitArr[i]>0 then
      ShowMessageFmt('%d bit = 1',[i]);
end;
procedure getBits(aByte:Byte; bitArr: array of Byte);overload;
asm
  mov ecx,0
  @@1:
  shr al,1
  jnc @@2
  mov [edx],1
  @@2:
  inc cx
  inc edx
  cmp ecx,8
  jnz @@1
end;

procedure getBits(aWord:Word; bitArr: array of Byte);overload;
asm
  mov ecx,0
  @@1:
  shr ax,1
  jnc @@2
  mov [edx],1
  @@2:
  inc cx
  inc edx
  cmp ecx,16
  jnz @@1
end;

posted @ 2011-05-23 11:09  Jekhn  阅读(870)  评论(0编辑  收藏  举报