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. SSRS 报表管理器 http://localhost/Reports HTTP500 内部错误处理过程

    原文地址:http://www.cnblogs.com/zzry/p/5716056.html 安装了很多机器的sqlserverBI 组件 初始安装配置下 浏览报表管理器 http://localh ...

  2. SEO搜索引擎优化基础

    要如何提高自己网站的知名度,那必须了解一些SEO知识. 1.什么是搜索引擎 所谓的搜索引擎(Search  Engines)是一些能够主动搜索信息(搜索网页上的单词和简短的特定的内容描述)并将其自动索 ...

  3. C++ STL map容器的说明测试1

    // maptest.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h" /*********************************** ...

  4. Python+Selenium练习篇之18-获取元素上面的文字

    本文介绍如何通过Selenium方法来获取某一个元素的text属性值.在很多自动化测试脚本中,需要多次获取元素的text值,拿过来进行对比和匹配.例如,在一个登陆界面,如果不输入用户名和密码,直接点击 ...

  5. thinkphp3.2接入支付宝支付接口(PC端)

    下载支付宝接口包    点击这里        提取密码:aryp 整个接口核心类文件 alipay.config.php是相关参数的配置文件 alipayapi.php 是支付宝接口入口文件 not ...

  6. CSU-1163 寒衣调

    CSU-1163 寒衣调 Description 男从戎,女守家.一夜,狼烟四起,男战死沙场.从此一道黄泉,两地离别.最后,女终于在等待中老去逝去.逝去的最后是换尽一生等到的相逢和团圆. 某日两人至奈 ...

  7. python 删除重复文件 附源代码

    啥也不说了,直接上源码 #! /usr/bin/env python #coding=utf-8 import os import md5 import time def getmd5( filena ...

  8. Ognl对象图导航语言 源码

    // -------------------------------------------------------------------------- // Copyright (c) 1998- ...

  9. Codeforces Round #440(Div.2)

    一句话题意: A:给出两个长为\(n\),\(m\)的的数组,每个数在\(1\)到\(9\)之间,求出一个最小的数使得至少有一位出现在一个数组中,且至少有一位出现在另一个数组中.\(n,m\leq9\ ...

  10. bzoj4380[POI2015]Myjnie dp

    [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 368  Solved: 185[S ...