delphi 비트레이트 연산
37267 단어 Delphi
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
w1: Word = 61680; { : 11110000 11110000}
w2: Word = 3855; { : 00001111 00001111}
var
w: Word;
{not , }
procedure TForm1.Button1Click(Sender: TObject);
begin
w := not w1;
{not ( ) }
{11110000 11110000 :}
{00001111 00001111 }
ShowMessage(IntToStr(w)); {3855}
end;
{and , }
procedure TForm1.Button2Click(Sender: TObject);
begin
w := w1 and w2;
{and , 1 1, 0}
{w1: 11110000 11110000 }
{w2: 00001111 00001111 , :}
{w : 00000000 00000000}
ShowMessage(IntToStr(w)); {0}
end;
{or , }
procedure TForm1.Button3Click(Sender: TObject);
begin
w := w1 or w2;
{and , 1 1; 0 0}
{w1: 11110000 11110000 }
{w2: 00001111 00001111 or :}
{w : 11111111 11111111}
ShowMessage(IntToStr(w)); {65535}
end;
{xor , }
procedure TForm1.Button4Click(Sender: TObject);
begin
w := w1 or w2;
{and , 1; ( 0 1) 0}
{w1: 11110000 11110000 }
{w2: 00001111 00001111 xor :}
{w : 11111111 11111111}
ShowMessage(IntToStr(w)); {65535; , xor or }
end;
{shr , }
procedure TForm1.Button5Click(Sender: TObject);
begin
w := w1 shr 1;
{shr , shr 1 }
{w1: 11110000 11110000 :}
{w : *1111000 01111000 * 0 }
ShowMessage(IntToStr(w)); {30840}
{ , , 3 }
w := w1 shr 3;
ShowMessage(IntToStr(w)); {7710}
{w1 shr 3 w1 div 2 3 }
w := w1 div 8;
ShowMessage(IntToStr(w)); {7710}
end;
{shl , }
procedure TForm1.Button6Click(Sender: TObject);
var
i: Integer;
begin
w := w1 shl 1