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. Python抓取视频内容

    Python抓取视频内容 Python 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年.Python语法简洁而清晰,具 ...

  2. Lucene.Net 精品教程

    http://www.cnblogs.com/piziyimao/archive/2013/01/31/2887072.html

  3. pycharm的常用操作:设置字体主题,注释整段代码,调整格式,批量替换等

    1.调出常用工具栏 调出的结果是下面这样的: 2.调出常用工具按钮 调出的结果如下: 3. 调整主题及文字大小 ps:如果设置后没变,需要多设置几次就好了. 4. 统一后退几格调整对齐格式 选中要调整 ...

  4. [错误解决]ubuntu 不在 sudoers 文件中。此事将被报告。

    跟据报错判断,ubuntu没有sudo权限,经过查询需要将ubuntu账户加入/etc/sudoers中 先切换到root权限 su 输入密码 修改/etc/sudoers配置 vim /etc/su ...

  5. 使用jsp读取TXT格式文件

    <%@page import="java.io.BufferedReader"%> <%@page import="java.io.FileReader ...

  6. 树中两个结点的最低公共祖先--java

    题目:对于任意一个树,不仅仅限于二叉树,求树中两个结点的最低公共祖先结点. 解析:对于任意一棵树,显然并不局限于二叉树,也就是说树的非叶子结点可能存在多个子节点.所以,我们可以定义两个链表结构,存储这 ...

  7. 【转】ugui自制摇杆

    http://www.cnblogs.com/duyushuang/p/4457691.html 珍爱生命,远离插件. 以上8个字,好好理解. 反正我是这么觉得. 我说的是unity,不是魔兽世界. ...

  8. MySQL Innodb表导致死锁日志情况分析与归纳

    发现当备份表格的sql语句与删除该表部分数据的sql语句同时运行时,mysql会检测出死锁,并打印出日志   案例描述在定时脚本运行过程中,发现当备份表格的sql语句与删除该表部分数据的sql语句同时 ...

  9. 第二篇:python基础_2

    本篇内容 数字 字符串 元祖 字典 列表 集合 for循环 二进制 字符编码 文件处理 一.数字 1.int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2 ...

  10. 习题:最短路计数(SPFA最短路计数)

    最短路计数(洛谷1144)题目描述 给出一个N个顶点M条边的无向无权图,顶点编号为1-N.问从顶点1开始,到其他每个点的最短路有几条.输入输出格式输入格式:输入第一行包含2个正整数N,M,为图的顶点数 ...