delphi 按位运算 not and or xor shl shr
2016-05-25 10:58
375 查看
delphi 按位运算 not and or xor shl shr
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Shape1: TShape;
Label1: TLabel;
Label2: TLabel;
Button7: TButton;
Button8: 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);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a: Word;
c: Integer;
begin
a := 6; //0000 0000 0000 0000 0000 0000 0000 0110
c := 12; //0000 0000 0000 0000 0000 0000 0000 1100 四字节 32 位
ShowMessage(IntToStr( a and c));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a, b: Word;
// a, b: Integer;
begin
a := 6;
b := 12;
ShowMessage(IntToStr(a and b));
//无符号:
// byte : 一个字节 8位 2的8次方 0-255 (2的8次方-1)
// word : 两个字节 16位 2的16次方 0-256*256 (65535)
// longword: 四个字节 32 2的32次方 0-65536*65536 (4294967295)
//
//有符号:(拿出一位做符号位,表示正负)
//shortint 一个字节 8位 2的8次方 -127-127 (256/2)
//smallint 两个字节 16位 2的16次方 -32767-32767 (256*256/2)
//longint(Ingetger) 四个字节32位 2的32次方 -2147483647-2147483647 (4294967295/2)
end;
//not
//1 -> 0 , 0 -> 1
procedure TForm1.Button3Click(Sender: TObject);
var
a: Word;
begin
a := 14; // 0000 0000 0000 1110
ShowMessage(IntToStr(not a)); //65521 not-> 1111 1111 1111 0001
end;
//and
//都是1才1
procedure TForm1.Button4Click(Sender: TObject);
var
a, b: Word;
begin
a := 14; // 0000 0000 0000 1110
b := 23; // 0000 0000 0001 0111
ShowMessage(IntToStr(a and b));//6 and->0000 0000 0000 0110
end;
//or
//位 有1则1
procedure TForm1.Button5Click(Sender: TObject);
var
a, b: Word;
begin
a := 14; // 0000 0000 0000 1110
b := 23; // 0000 0000 0001 0111
ShowMessage(IntToStr(a or b));//31 and->0000 0000 0001 1111
end;
//xor
//位不相同1
procedure TForm1.Button6Click(Sender: TObject);
var
a, b: Word;
begin
a := 14; // 0000 0000 0000 1110
b := 23; // 0000 0000 0001 0111
ShowMessage(IntToStr(a xor b));//25 and->0000 0000 0001 1001
end;
//shl
//说明:左移 右边补0 (超出忽略)
procedure TForm1.Button7Click(Sender: TObject);
var
a: Word;
b: Byte;
begin
a := 14; // 0000 0000 0000 1110
ShowMessage(IntToStr(a shl 1));//28 and->0000 0000 0001 1100
ShowMessage(IntToStr(a shl 3));//112 and->0000 0000 0111 0000
b :=12; // 0000 1100;
ShowMessage(IntToStr(b shl 4)); //192 1100 0000
ShowMessage(IntToStr(b shl 5)); //384 11000 0000
// 6 // 11 0000 0000 (超出忽略)
end;
//shr
//说明:右移 左边补0 (超出忽略)
procedure TForm1.Button8Click(Sender: TObject);
var
a: Word;
begin
a := 14; // 0000 0000 0000 1110
ShowMessage(IntToStr(a shr 1));//7 shr->0000 0000 0000 0111
ShowMessage(IntToStr(a shr 2));//3 shr->0000 0000 0000 0011
//3 0000 0000 0000 0001
//4 0000 0000 0000 0000 (超出忽略)
end;
end.
相关文章推荐
- 求用delphi编写的LRC校验位算法函数,急!!!
- Delphi XE3 代码自动提示bug的解决
- delphi 在DLL中添加窗体
- 怎么把一个整数转化为3个十六进制字节 delphi
- Delphi的学习笔记八——内存操作函数
- Delphi的学习笔记七——格式化输出函数(总结的很全面)
- Delphi 7下使用Log4Delphi 0.8日志组件
- Delphi RAD Berlin OutputDebugString 输出调试信息
- Delphi学习笔记六——文件路径相关的字符串操作
- Delphi学习笔记五——方法
- Delphi 中ASSERT用法
- RAD Studio, Delphi, C++Builder 10.1 Berlin第二季优惠活动
- delphi 线程同步的基本方法
- 一个简单的MDI示范程序(Delphi)
- Delphi学习笔记四——语句
- Delphi学习笔记三——运算符
- Delphi学习笔记二——数据类型
- Delphi学习笔记一——Delphi的项目文件简介
- 160个CrackMe 001 Acid burn
- Delphi十进制和十六进制互转