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 按位运算 not and or xor shl shr的更多相关文章

  1. LeetCode - 136. Single Number - ( C++ ) - 解题报告 - 位运算思路 xor

    1.题目大意 Given an array of integers, every element appears twice except for one. Find that single one. ...

  2. Xor Sum 2(位运算)

    D - Xor Sum 2 Time limit : 2sec / Memory limit : 1024MB Score : 500 points Problem Statement There i ...

  3. 简简单单学会C#位运算

    一.理解位运算 要学会位运算,首先要清楚什么是位运算?程序中的所有内容在计算机内存中都是以二进制的形式储存的(即:0或1),位运算就是直接对在内存中的二进制数的每位进行运算操作 二.理解数字进制 上面 ...

  4. Java中的位运算

    昨天去面试的时候做到了一道Java的位运算题目,发现有个运算符不懂:">>>",今天特地查了一下,并小结一下常见的位运算符号: ~  按位非(NOT)(一元运算) ...

  5. CodeForces 282C(位运算)

    C. XOR and OR time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. BZOJ-3668 起床困难综合症 位运算+贪心

    faebdc学长杂题选讲中的题目...还是蛮简单的...位运算写的不熟练... 3668: [Noi2014]起床困难综合症 Time Limit: 10 Sec Memory Limit: 512 ...

  7. 位运算(bit)

    位运算(bit) Time Limit:2000ms   Memory Limit:64MB [题目描述] lyk最近在研究位运算.它发现除了xor,or,and外还有很多运算.它新定义了一种运算符“ ...

  8. Matlab位运算笔记

    本文为转载其他地方的文章; MATLAB函数 1.matlab函数bitset 设置数的某一位二进制位为1. <Simulink与信号处理> 使用方法 C = bitset(A,bit) ...

  9. C语言的位运算

    位运算加速技巧1. 如果乘上一个2的倍数数值,可以改用左移运算(Left Shift) 加速 300% x = x * 2;x = x * 64;//改为:x = x << 1; // 2 ...

随机推荐

  1. loj2173 「FJOI2016」建筑师

    ref 真是道组合数学神题啊--第一次见第一类斯特林数-- #include <iostream> #include <cstdio> using namespace std; ...

  2. 部署 Windows PowerShell Web 访问

    部署 Windows PowerShell Web 访问 适用对象:Windows Server 2012, Windows Server 2012 R2 Windows PowerShell® We ...

  3. MongoDB用PCRE正则表达式

    介绍 下面说明 PCRE 所支持的正则表达式的语法和语义.Perl 文档和很多其它书中也解说了正则表达式,有的书中有很多例子.Jeffrey Friedl 写的“Mastering Regular E ...

  4. jmeter连接数据库之增删改查

    配置jdbc: 查询sql配置: 插入sql配置: 修改sql配置: 删除sql配置:

  5. Leetcode 632.最小区间

    最小区间 你有 k 个升序排列的整数数组.找到一个最小区间,使得 k 个列表中的每个列表至少有一个数包含在其中. 我们定义如果 b-a < d-c 或者在 b-a == d-c 时 a < ...

  6. RESTful-rest_framework视图层-第三篇

    图书管理系统: 实现图书接口的增.删.改.查 方式一:普通的方式 views配置: #Book的增.删.改.查接口 class BookSerializer(serializers.ModelSeri ...

  7. 贪吃蛇—C—基于easyx图形库(下):从画图程序到贪吃蛇【自带穿墙术】

    上节我们用方向控制函数写了个小画图程序,它虽然简单好玩,但我们不应该止步于此.革命尚未成功,同志还需努力. 开始撸代码之前,我们先理清一下思路.和前面画图程序不同,贪吃蛇可以有很多节,可以用一个足够大 ...

  8. POJ2796 Feel Good -- 单调队列

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 4015 Case T ...

  9. Mysql存储过程从0开始(上)

    1.首先你要明白,mysql也是一种语言,他也可以编写程序,也是支持逻辑判断,if,elseif,else,switch,while等等的判断 2.mysql赋值一个变量的值操作:set @a = 1 ...

  10. [国家集训队][bzoj 2152] 聪聪可可 [点分治]

    题面: http://www.lydsy.com/JudgeOnline/problem.php?id=2152 思路: 题目要求统计书上路径信息,想到树上分治算法 实际上这是一道点分治裸题,我就不瞎 ...