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. Nodejs-非阻塞I/O&事件驱动

    1.关于es6变量 const 定义常量,不会发生改变的就用这个 let 定义局部变量 如: const fs=require('fs');//require()表示载入这个模块 function a ...

  2. IOS开发学习笔记020-练习总结

    自己做了一遍,现在再复习一下,总结一下. 最终效果如下         1.新建一个工程Single View Application 总体如下 不过要关闭自动布局功能 这是按下设置按钮显示的界面默认 ...

  3. Django中从本地上传excel文件并将数据存储到数据库

    Django中从本地上传excel文件并将数据存储到数据库 一.前端界面 <div class="page-container"> <form action=&q ...

  4. 【LeetCode】Remove Duplicates from Sorted List(删除排序链表中的重复元素)

    这道题是LeetCode里的第83道题. 题目描述: 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示例 2: ...

  5. line-height与vertical-align

    css世界读书笔记: 内联元素与流 块级元素负责结构,内联元素接管内容 x元素的下边缘就是我们的基线baseline x-height就是x的高度 vertical-align:middle是x中点位 ...

  6. script error总结

    移动端的页面在控制台报出一个script error,通常的原因有一下几点: 1. 脚本引入错误 可能是脚本的地址不对,协议不对(http或https问题),本地host文件绑定的地址不对 2. 方法 ...

  7. SELECT中的CAST

    SELECT CAST a.b AS int 语法意义 把表别名A的B列的数据类型变为INT

  8. python转exe2

    转载自 xiake200704       最终编辑 xiake200704 一.简介 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你 ...

  9. 判断是手机端还是pc端

    <script type="text/javascript"> if (window.location.toString().indexOf('pref=padinde ...

  10. godaddy虚拟空间的伪静态配置

    原文发布时间为:2011-02-24 -- 来源于本人的百度文章 [由搬家工具导入] 只要在web.config文件的<configuration>子节点下 加入以下节点,即可实现 伪静态 ...