mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
DotNET

C#运算符之与,或,异或及移位运算

C#运算符之与,或,异或及移位运算 1.剖析异或运算(^) 二元 ^ 运算符是为整型和 bool 类型预定义的。对于整型,^ 将计算操作数的按位“异或”。对于 bool 操作数,^ 将计算操作数的逻辑“异或”;也就是说,当且仅当只有一个操作数为 true 时,结果才为 true。 数值运算举例 按位异或的3个特点: (1) 0^0=0,0^1=1  0异或任何数=任何数 (2) 1^0=1,1^1=0  1异或任何数-任何数取反 (3) 1^1=0,0^0=0  任何数异或自己=把自己置0 例如:10100001^00010001=10110000 按位异或的几个常见用途: (1) 使某些特定的位翻转     例如对数10100001的第2位和第3位翻转,则可以将该数与00000110进行按位异或运算。        10100001^00000110 = 10100111 (2) 实现两个值的交换,而不必使用临时变量。     例如交换两个整数a=10100001,b=00000110的值,可通过下列语句实现:     a = a^b;   //a=10100111     b = b^a;   //b=10100001     a = a^b;   //a=00000110 (3) 在汇编语言中经常用于将变量置零:     xor   a,a (4) 快速判断两个值是否相等     举例1: 判断两个整数a,b是否相等,则可通过下列语句实现:         return ((a ^ b) == 0)        举例2: Linux中最初的ipv6_addr_equal()函数的实现如下:     static inline int ipv6_addr_equal(const struct in6_addr *a1, const struct in6_addr *a2)     {         return (a1->s6_addr32[0] == a2->s6_addr32[0] &&             a1->s6_addr32[1] == a2->s6_addr32[1] &&             a1->s6_addr32[2] == a2->s6_addr32[2] &&             a1->s6_addr32[3] == a2->s6_addr32[3]);     }        可以利用按位异或实现快速比较, 最新的实现已经修改为:     static inline int ipv6_addr_equal(const struct in6_addr *a1, const struct in6_addr *a2)     {     return (((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |         (a1->s6_addr32[1] ^ a2->s6_addr32[1]) |         (a1->s6_addr32[2] ^ a2->s6_addr32[2]) |         (a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0);     } 2 & 运算符(与) 1 & 0 为0 0 & 0 为0 1 & 1 为1 3 | 运算符(或) 1 | 0 为1 0 | 0 为0 1 | 1 为1 ------------------ C#移位运算(左移和右移)     C#是用<<(左移) 和 >>(右移) 运算符是用来执行移位运算。   左移 (<<)   将第一个操作数向左移动第二个操作数指定的位数,空出的位置补0。   左移相当于乘. 左移一位相当于乘2;左移两位相当于乘4;左移三位相当于乘8。   x<<1= x*2   x<<2= x*4   x<<3= x*8   x<<4= x*16   同理, 右移即相反:   右移 (>>)   将第一个操作数向右移动第二个操作数所指定的位数,空出的位置补0。   右移相当于整除. 右移一位相当于除以2;右移两位相当于除以4;右移三位相当于除以8。   x>>1= x/2   x>>2= x/4   x>>3= x/8   x>>4=x/16 如  int i = 7;  int j = 2;  Console.WriteLine(i >> j);   //输出结果为1   当声明重载C#移位运算符时,第一个操作数的类型必须总是包含运算符声明的类或结构,并且第二个操作数的类型必须总是 int,如: class Program   {        static void Main(string[] args)        {             ShiftClass shift1 = new ShiftClass(5,…

2015-10-17 0comments 129hotness 0likes mikebai Read all
dev

Big-endian 和 Little-endian

Big-endian  Little-endian are two different methods used by the MCU and MPU for storing data in memory for quantity more then a single byte little-endian storage is starting from the least significant byte to finish with the most significant, is used by ARM CORTEX. big-endian storage is starting from most significant byte to finish with the least significant.

2015-10-16 0comments 109hotness 0likes mikebai Read all
dev

python数组索引范围

It's pretty simple really: a[start:end] # items start through end-1 a[start

2015-10-13 0comments 120hotness 0likes mikebai Read all
dev

python unpack 参数

struct 类型表 Format C Type Python type Standard size Notes x pad byte no value     c char string of length 1 1   b signed char integer 1 (3) B

2015-10-13 0comments 120hotness 0likes mikebai Read all
dev

android apn setting info

DefaultApn/ProfileName \system\csc\others.xml Your phones default APN settings are stored on the phone in a file here \system\etc\apns-conf.xml [APP] Turn Off Camera Shutter Sound http://forum.xda-developers.com/note-edge/themes-apps/app-off-camera-shutter-sound-t3040627 SCL24 NOTE EDGE SHUTTER SOUND OPTION /system/csc/feature.xml <CscFeature_Camera_ShutterSoundMenu>true</CscFeature_Camera_ShutterSoundMenu>

2015-07-27 0comments 104hotness 0likes mikebai Read all
DotNET

HttpWebRequest

https://weblog.west-wind.com/posts/2010/Feb/18/NET-WebRequestPreAuthenticate-not-quite-what-it-sounds-like

2015-06-30 0comments 110hotness 0likes mikebai Read all
漂在日本

各国常用经济指标

失业率  Unemployment 它作为反映一国宏观经济发展的晴雨表,预示着该国经济当前与前景发展的好坏,势必影响了货币政策的制定,对汇率产生重大影响。 非农就业人口  Nonfarm payroll employment 美国的就业报告数据,与失业率一同公布。通常公布时间为每月第一周的周五。 国民生产总值  GNP 目前各国每季度公布一次,它以货币形式表现了该国在一个时期内所有部门的全部生产与服务的总和,是不同经济数据的综合表现,反映了当前经济发展的状况 国内生产总值  GDP 目前各国每季度公布一次,显示了该国在一定时期境内的全部经济活动,包括外国公司在其境内投资建立子公司所产生的营利。 生产价格(物价)指数  PPI 显示了商品生产的成本(生产原材料价格的变化),对未来商品价格的变化,从而影响了今后消费价格、消费心理的改变。

2015-03-01 0comments 130hotness 0likes mikebai Read all
DotNET

barcoce note

http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/ http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard

2014-08-26 0comments 126hotness 0likes mikebai Read all
dev

Encode Keyboard FNC Keys in a Barcode

Encode Keyboard FNC Keys in a Barcode The IDAutomation SC5-USB Barcode Scanner has the capability of scanning keyboard function keys (such as F2, F4, F10, etc.) from a properly encoded barcode, providing that function key emulation option is enabled within the scanner. Solution(s): The built in decoder for the IDAutomation SC5USB Barcode Scanner can emulate function keys as well as other keys such as PgUp, PgDn, Backspace, Tab, Enter, Esc, Insert, Delete, Home and End. Enable the "Function Key Emulation Mode" by scanning the appropriate barcode in the scanner manual. When enabled, lower ASCII codes in a Code 128 barcode will simulate pressing a function key on the keyboard. For example, an ASCII 23 digit (0x17 in the manual) encoded in a barcode will send the same codes to the computer as if the F7 function key was pressed. Because the scanner manual only lists hexadecimal numbers, refer to the ASCII chart for conversions. IDAutomation suggests using Set A of Code 128 to easily encode lower ASCII characters. For example, the following encoded in Code 128 Set A simulates pressing the F7 key after the data "123456" is entered: 123456w This barcode may be printed for testing purposes from the following URL: http://www.bcgen.com/demo/linear-dbgs.aspx?S=13&CS=1&D=123456m Functions ASCII Extended Code 39 Equivalent * Code 128 Set A Equivalent Hex Value Description F1 17 $Q q 11 DC1 F2 18 $R r 12 DC2 F3 19 $S

2014-08-20 0comments 114hotness 0likes mikebai Read all
DotNET

bind class to grid note

http://stackoverflow.com/questions/16695885/binding-listt-to-datagridview-in-winform http://msdn.microsoft.com/en-us/library/y0wfd4yz%28v=vs.90%29.aspx

2014-08-07 0comments 119hotness 0likes mikebai Read all
1…2728293031…62

Recent Posts

  • c# winform适配高dpi
  • com.microsoft.sqlserver.jdbc.SQLServerException “trustServerCertificate”属性设置为“false”,但驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server建立安全连接
  • java -cp 用法介绍
  • HTML 容器元素
  • MVC的cshtml的介绍

Recent Comments

No comments to show.

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang