delphi 按位运算 not and or xor shl shr

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.

时间: 2024-08-24 01:55:55

delphi 按位运算 not and or xor shl shr的相关文章

hdu 5344 (多校联赛) MZL's xor --- 位运算

here:    首先看一下题吧:题意就是让你把一个序列里所有的(Ai+Aj) 的异或求出来.(1<=i,j<=n) Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1≤i,j≤n) The xor of an array B is defined as B1 xor B2...xor B

HDU 4825 Xor Sum 字典树+位运算

点击打开链接 Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 291    Accepted Submission(s): 151 Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus

Xor Sum 2(位运算)

D - Xor Sum 2 Time limit : 2sec / Memory limit : 1024MB Score : 500 points Problem Statement There is an integer sequence A of length N. Find the number of the pairs of integers l and r (1≤l≤r≤N) that satisfy the following condition: Al xor Al+1 xor 

mysql位运算

1.MOD(X1,X2) 求余运算,返回余数同"%" 2.X1 DIV X2 除法运算返回商,同"/" 3.如果除数为0,那么结果为NULL. 4.<=>和= 是一样的,也是用来判断操作数是否相等的.不同的是<=>可以用来判断null,=不能判断null. 例:select null<=>null 结果1 逻辑运算符 1.与&&或and:所有操作数不为0且不为null时,结果为1,任何一操作数为0,结果为0,存在一

C位运算笔记(根据网上内容整理)1

什么是位运算?    程序中的所有数在计算机内存中都是以二进制的形式储存的.位运算说穿了,就是直接对整数在内存中的二进制位进行操作.由于位运算直接对内存数据进行操作,不需要转成十进制,因此处理速度非常快. 各种位运算的使用 === 1. and运算 ===(同真为真) and运算通常用于二进制取位操作,例如一个数 and 1的结果就是取二进制的最末位.这可以用来判断一个整数的奇偶,二进制的最末位为0表示该数为偶数,最末位为1表示该数为奇数. === 2. or运算 ===(一真为真) or运算通

java位运算

Java的位运算(bitwise operators)直接对整数类型的位进行操作,这些整数类型包括long.int.short.char和 byte,位运算符具体如下表: 运算符 说明 << 左移位,在低位处补0 >> 右移位,若为正数则高位补0,若为负数则高位补1 >>> 无符号右移位,无论正负都在高位补0 & 与(AND),对两个整型操作数中对应位执行布尔代数,两个位都为1时输出1,否则0. | 或(OR),对两个整型操作数中对应位执行布尔代数,两个位

golang的位运算操作符的使用

& 位运算 AND | 位运算 OR ^ 位运算 XOR &^ 位清空 (AND NOT) << 左移 >> 右移 感觉位运算操作符虽然在平时用得并不多,但是在涉及到底层性能优化或者使用某些trick的时候还是比较有意思. &(AND) |(OR) 就不提了最常用的东西 会编程就会. ^(XOR) 在go语言中XOR是作为二元运算符存在的: 但是如果是作为一元运算符出现,他的意思是按位取反,例如 package main import "fmt&q

javascript中的类型转换(进制转换|位运算)

1:parseInt(string) : 这个函数的功能是从string的开头开始解析,返回一个整数 parseInt("123hua"); //输出 123 parseInt("123"); //输出 123 parseInt("12.3"); //输出 12 parseInt("hua"); //输出 Nan 2:另外parseInt()方法还有其他模式,就是可以把二进制.八进制.十六进制或其他任何进制的字符串转换成整数

[leetcode] Sum of Two Integers--用位运算实现加法运算

问题: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. 分析: 这里要求我们不能用加法.减法等运算符来实现加法运算.这里应该使用位运算来实现加法运算,实际上,这也是计算机CPU内部实现加法运算的方案. x XOR y真值表: x y output 0 0 0 0 1 1